From 70d93acb1571c6f08e93070ee2cbe14dcbafa0b7 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 24 May 2020 12:55:20 +0200 Subject: [PATCH] Added git completion to zsh --- fzf/git-completion.zsh | 16 ++++++++++++++++ zsh/zshrc | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 fzf/git-completion.zsh diff --git a/fzf/git-completion.zsh b/fzf/git-completion.zsh new file mode 100644 index 0000000..27b3c29 --- /dev/null +++ b/fzf/git-completion.zsh @@ -0,0 +1,16 @@ +_fzf_complete_git() { + ARGS="$@" + local branches + branches=$(git branch --all --sort=-committerdate --format="%(refname:short)") + if [[ $ARGS == 'git co'* || $ARGS == 'git checkout'* || $ARGS == 'git merge'* ]]; then + _fzf_complete -- "$@" < <( + echo $branches + ) + else + eval "zle ${fzf_default_compeltion:-expand-or-complete}" + fi +} + +_fzf_complete_git_post() { + sed "s/^origin\///" +} diff --git a/zsh/zshrc b/zsh/zshrc index 37b08b8..37bd72b 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -112,3 +112,5 @@ export EDITOR='nvim' # alias ohmyzsh="mate ~/.oh-my-zsh" [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh +[ -f ~/.dotfiles/fzf/git-completion.zsh ] && source ~/.dotfiles/fzf/git-completion.zsh +