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

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