Created
February 2, 2018 17:06
-
-
Save squidarth/bbfa7c203ab33cf416afd570dd760322 to your computer and use it in GitHub Desktop.
zsh fzf history search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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