zsh: cd to git repository root with ctrl-g in the line editor
This commit is contained in:
parent
d28bb6099f
commit
c3b1b29768
1 changed files with 11 additions and 0 deletions
|
@ -52,6 +52,17 @@ bindkey -M viins '^[f' vi-forward-word
|
||||||
# Shortcut to start neovim.
|
# Shortcut to start neovim.
|
||||||
bindkey -s '^v' '^unvim\r'
|
bindkey -s '^v' '^unvim\r'
|
||||||
|
|
||||||
|
# cd to the root of the git repository (if within one).
|
||||||
|
cd-git-root() {
|
||||||
|
local top_level="$(git rev-parse --show-toplevel 2>/dev/null)"
|
||||||
|
[[ -z "$top_level" ]] && return 1
|
||||||
|
zle push-line
|
||||||
|
BUFFER="builtin cd -- ${(q)top_level}"
|
||||||
|
zle accept-line
|
||||||
|
}
|
||||||
|
zle -N cd-git-root
|
||||||
|
bindkey -M viins '^g' cd-git-root
|
||||||
|
|
||||||
if command -v fzf >/dev/null 2>&1; then
|
if command -v fzf >/dev/null 2>&1; then
|
||||||
# Add `fzf` key bindings if it's installed:
|
# Add `fzf` key bindings if it's installed:
|
||||||
# - CTRL-T: paste the selected file path(s) into the command line
|
# - CTRL-T: paste the selected file path(s) into the command line
|
||||||
|
|
Loading…
Add table
Reference in a new issue