Skip to content

Instantly share code, notes, and snippets.

@squidarth
Created February 2, 2018 17:06
Show Gist options
  • Save squidarth/bbfa7c203ab33cf416afd570dd760322 to your computer and use it in GitHub Desktop.
Save squidarth/bbfa7c203ab33cf416afd570dd760322 to your computer and use it in GitHub Desktop.
zsh fzf history search
fzf-history-widget() {
local selected restore_no_bang_hist
if selected=$(fc -l 1 | fzf +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER"); then
num=$(echo "$selected" | head -1 | awk '{print $1}' | sed 's/[^0-9]//g')
LBUFFER=!$num
if setopt | grep nobanghist > /dev/null; then
restore_no_bang_hist=1
unsetopt no_bang_hist
fi
zle expand-history
[ -n "$restore_no_bang_hist" ] && setopt no_bang_hist
fi
zle accept-line
}
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment