Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opennomad/18280decfcabdb7d54e8c257a3a07da3 to your computer and use it in GitHub Desktop.
Save opennomad/18280decfcabdb7d54e8c257a3a07da3 to your computer and use it in GitHub Desktop.
Use peco (https://github.com/peco/peco) to search ZSH's history via ctrl+R
if [[ "$(command -v peco)" ]]; then
# Search shell history with peco: https://github.com/peco/peco
# Adapted from: https://github.com/mooz/percol#zsh-history-search
function peco_select_history() {
BUFFER=$(fc -lnr 1 | peco --initial-filter Regexp --query "$LBUFFER")
CURSOR=$#BUFFER # move cursor
zle -R -c # refresh
}
zle -N peco_select_history
bindkey '^R' peco_select_history
fi
@opennomad
Copy link
Author

Using the quicker command rather than which to see if peco installed and -r rather than tac etc to reverse the history.

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