cd to git repo with zsh and fzf

Navigate to any git checkout dir

In my .zshrc I have defined this function:

cdgit() {
    local dir=
    dir=$(
      stdbuf --output=L \
        find "$HOME/src" -maxdepth 4 -type d -name .git |
        sed -u 's#/\.git$##' |
        fzf)

    if [[ -n "${dir}" ]]; then
        cd "${dir}" || exit 1
        zle reset-prompt
    fi
}

Create a zle widget and bind it to cdgit

Also in .zshrc, I bind it to a shortcut, I like Ctrl + g:

zle -N cdgit
bindkey '^G' cdgit

~ /home 🏠 ~ talks 💬 ~ bash ~ craftsmanship ~ db ~ dongxi ~ emacs ~ escenic ~ iam ~ java ~ js ~ language ~ latex ~ ldap ~ life ~ linux ~ llm ~ mac-os-x ~ mt-foo ~ network ~ norsk ~ python ~ quotes ~ running ~ security ~ travel ~ unix ~ various ~ vcs ~ webdesign ~ windows ~ discoveries ~ cv 🧙 ~

Licensed under CC BY Creative Commons License ~ 📡 RSS feed ~ ✉ torstein.k.johansen @ gmail ~ 🐘 @skybert@hachyderm.io ~ 🎥 youtube.com/@skybert