diff options
author | William Carroll <wpcarro@gmail.com> | 2017-05-27T20·24-0400 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2017-05-27T20·24-0400 |
commit | 24f25f17c1b79f73c7c88e412a72f743b30db7ff (patch) | |
tree | 9cacc46a3dd0d45e0262f88c27e7557e44ecccbd | |
parent | fd83169d4f1dbe8e5a5ebac29bc6ea2ade15d642 (diff) |
Adds keybinding support for fzf git branch finding
-rw-r--r-- | configs/.zsh_profile | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/configs/.zsh_profile b/configs/.zsh_profile index 5e76a9d800d3..befb2529b4a7 100644 --- a/configs/.zsh_profile +++ b/configs/.zsh_profile @@ -1,4 +1,4 @@ -export PATH=/Users/wpcarro/bin:/opt/local/bin:/opt/local/sbin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/fzf/bin:/Users/wpcarro/n/bin +export PATH=$HOME/bin:/opt/local/bin:/opt/local/sbin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/fzf/bin:$HOME/n/bin:$HOME/.cargo/bin # make vim the default editor for commit messages etc export EDITOR=$(which vim) @@ -52,6 +52,28 @@ stty -ixon export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -l -g ""' export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" +# CTRL-Y - Paste the selected branch(es) into the command line +__bsel() { + local cmd="git branch -a | tr -d '* ' | sed 's/^remotes\/origin\///' | sort | uniq" + setopt localoptions pipefail 2> /dev/null + eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read item; do + echo -n "${(q)item} " + done + local ret=$? + echo + return $ret +} + +fzf-branch-widget() { + LBUFFER="${LBUFFER}$(__bsel)" + local ret=$? + zle redisplay + typeset -f zle-line-init >/dev/null && zle zle-line-init + return $ret +} +zle -N fzf-branch-widget +bindkey '^Y' fzf-branch-widget + # Run Autojump at shell startup [[ $(brew --prefix)/etc/profile.d/autojump.sh ]] && \ |