Skip to content

Instantly share code, notes, and snippets.

@stephanschubert
Last active August 23, 2016 10:20
Show Gist options
  • Select an option

  • Save stephanschubert/94ab20ec172589419a27 to your computer and use it in GitHub Desktop.

Select an option

Save stephanschubert/94ab20ec172589419a27 to your computer and use it in GitHub Desktop.
Reverse command history search with selecta's fuzzy matching for ZSH
function exists { which $1 &> /dev/null }
if exists selecta; then
function selecta_select_history() {
local tac
exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } }
BUFFER=$(fc -l -n 1 | eval $tac | selecta $LBUFFER)
CURSOR=$#BUFFER # move cursor
zle -R -c # refresh
}
zle -N selecta_select_history
bindkey '^R' selecta_select_history
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment