Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save yuttie/2aeaecdba24256c73bf2 to your computer and use it in GitHub Desktop.
Save yuttie/2aeaecdba24256c73bf2 to your computer and use it in GitHub Desktop.
Use peco (https://github.com/peco/peco) to search ZSH's history via ctrl+R
# Search shell history with peco: https://github.com/peco/peco
# Adapted from: https://github.com/mooz/percol#zsh-history-search
if which peco &> /dev/null; then
function peco_select_history() {
local tac
{ which gtac &> /dev/null && tac="gtac" } || \
{ which tac &> /dev/null && tac="tac" } || \
tac="tail -r"
BUFFER=$(fc -l -n 1 | eval $tac | \
peco --layout=bottom-up --query "$LBUFFER")
CURSOR=$#BUFFER # move cursor
zle -R -c # refresh
}
zle -N peco_select_history
bindkey '^R' peco_select_history
fi
@yuttie
Copy link
Author

yuttie commented Oct 15, 2015

changed: Don't try to set a local variable 'tac' inside a subshell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment