From 45f4f72eb7418f55e5015babd2598ee85c0ee25a Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Wed, 27 Jul 2022 12:08:42 +0200 Subject: [PATCH] zsh: widget to cd to any dir in a git repo on C-/ --- .zshrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.zshrc b/.zshrc index c790c72..9196c17 100644 --- a/.zshrc +++ b/.zshrc @@ -77,6 +77,14 @@ fre_chpwd() { typeset -gaU chpwd_functions chpwd_functions+=fre_chpwd +_cwd_gitroot() { + _gitroot=$(git rev-parse --show-toplevel 2>/dev/null || pwd) + _dir=$((echo "$_gitroot" && fd -td . "$_gitroot") | fzf-tmux) + [ -n "$_dir" ] && cd $_dir + zle && zle redraw-prompt +} +zle -N _cwd_gitroot + ## Keybindings bindkey -e bindkey '^[[A' history-beginning-search-backward @@ -84,6 +92,7 @@ bindkey '^[[B' history-beginning-search-forward bindkey '^P' history-beginning-search-backward bindkey '^N' history-beginning-search-forward bindkey '^g' _jump +bindkey '^_' _cwd_gitroot ## Gnupg / gpg / ssh / yubikey