diff --git a/shell/zsh/custom/plugins/peco-history/peco-history.plugin.zsh b/shell/zsh/custom/plugins/peco-history/peco-history.plugin.zsh new file mode 100644 index 0000000..8ed5470 --- /dev/null +++ b/shell/zsh/custom/plugins/peco-history/peco-history.plugin.zsh @@ -0,0 +1,19 @@ +# History search with peco +# +# 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 diff --git a/shell/zshrc.sh b/shell/zshrc.sh index 443240d..0dc7bba 100644 --- a/shell/zshrc.sh +++ b/shell/zshrc.sh @@ -34,8 +34,23 @@ DISABLE_AUTO_TITLE="true" # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) # Example format: plugins=(rails git textmate ruby lighthouse) -plugins=(brew bundler cake cap gem heroku node nyan osx powder python ruby \ - thor vagrant) +plugins=( \ + brew \ + bundler \ + cake \ + cap \ + gem \ + heroku \ + node \ + nyan \ + osx \ + peco-history \ + powder \ + python \ + ruby \ + thor \ + vagrant \ +) source "$ZSH/oh-my-zsh.sh" @@ -85,25 +100,3 @@ zle -N zle-line-init # use ctrl+t to toggle autosuggestions(hopefully this wont be needed as # zsh-autosuggestions is designed to be unobtrusive) bindkey '^T' autosuggest-toggle - - -# -# History search with peco -# - -# 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 percol_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 --query "$LBUFFER") - CURSOR=$#BUFFER # move cursor - zle -R -c # refresh - } - - zle -N percol_select_history - bindkey '^R' percol_select_history -fi