diff options
Diffstat (limited to 'plugins/percol/percol.plugin.zsh')
-rw-r--r-- | plugins/percol/percol.plugin.zsh | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/plugins/percol/percol.plugin.zsh b/plugins/percol/percol.plugin.zsh index c6adf4e1e..b78383eee 100644 --- a/plugins/percol/percol.plugin.zsh +++ b/plugins/percol/percol.plugin.zsh @@ -1,22 +1,25 @@ -if which percol &> /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 | percol --query "$LBUFFER") - CURSOR=$#BUFFER - zle -R -c - } +(( ${+commands[percol]} )) || return - zle -N percol_select_history - bindkey '^R' percol_select_history +function percol_select_history() { + # print history in reverse order (from -1 (latest) to 1 (oldest)) + BUFFER=$(fc -l -n -1 1 | percol --query "$LBUFFER") + CURSOR=$#BUFFER + zle -R -c +} +zle -N percol_select_history +bindkey -M emacs '^R' percol_select_history +bindkey -M viins '^R' percol_select_history +bindkey -M vicmd '^R' percol_select_history - if which marks &> /dev/null; then - function percol_select_marks() { - BUFFER=$(marks | percol --query "$LBUFFER" | awk '{print $3}') - CURSOR=$#BUFFER # move cursor - zle -R -c # refresh - } - zle -N percol_select_marks - bindkey '^B' percol_select_marks - fi +if (( ${+functions[marks]} )); then + function percol_select_marks() { + # parse directory from marks output (markname -> path) and quote if necessary + BUFFER=${(q)"$(marks | percol --query "$LBUFFER")"##*-> } + CURSOR=$#BUFFER + zle -R -c + } + zle -N percol_select_marks + bindkey -M emacs '^B' percol_select_marks + bindkey -M viins '^B' percol_select_marks + bindkey -M vicmd '^B' percol_select_marks fi |