refactor(percol): fix style, bind keys for vi-mode and remove dependencies
Diff
1diff --git a/plugins/percol/README.md b/plugins/percol/README.md
2index ec5de4f86bd232f6b468c4669f4f603a6f5ab804..78c881f550a91fd318dbfa775c6570efa77cb66a 100644
3--- a/plugins/percol/README.md
4+++ b/plugins/percol/README.md
5@@ -1,20 +1,23 @@
6-## percol
7+# percol
8 9-Provides some useful function to make [percol](https://github.com/mooz/percol) work with zsh history and [jump plugin](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/jump/jump.plugin.zsh)
10+Provides some useful function to make [percol](https://github.com/mooz/percol) work with zsh history and
11+the [jump plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/jump), optionally.
1213-### Requirements
14+To use it, add `percol` to the plugins array in your zshrc:
1516-```shell
17-pip install percol
18+```zsh
19+plugins=(... percol)
20 ```
2122-And [jump](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/jump/jump.plugin.zsh) for `oh-my-zsh` is a optional requirement.
23+## Requirements
2425-### Usage
26+- `percol`: install with `pip install percol`.
2728-For default
29+- (_Optional_) [`jump`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/jump) plugin: needs to be
30+ enabled before the `percol` plugin.
3132-- `^-r` bind to `percol_select_history`.You can use it to grep your history with percol.
33+## Usage
3435-- `^-b` bind to `percol_select_marks`.You can use it to grep your bookmarks with percol.
36+- <kbd>CTRL-R</kbd> (bound to `percol_select_history`): you can use it to grep your history with percol.
3738+- <kbd>CTRL-B</kbd> (bound to `percol_select_marks`): you can use it to grep your jump bookmarks with percol.
39diff --git a/plugins/percol/percol.plugin.zsh b/plugins/percol/percol.plugin.zsh
40index c6adf4e1eeff3a3c96fa68b64d6c68306aa140c6..b78383eee2191ead1fb8b5675cb81b1a7c4faf63 100644
41--- a/plugins/percol/percol.plugin.zsh
42+++ b/plugins/percol/percol.plugin.zsh
43@@ -1,22 +1,25 @@
44-if which percol &> /dev/null; then
45- function percol_select_history() {
46- local tac
47- which gtac &> /dev/null && tac="gtac" || { which tac &> /dev/null && tac="tac" || { tac="tail -r" } }
48- BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
49- CURSOR=$#BUFFER
50- zle -R -c
51- }
52+(( ${+commands[percol]} )) || return
5354- zle -N percol_select_history
55- bindkey '^R' percol_select_history
56+function percol_select_history() {
57+ # print history in reverse order (from -1 (latest) to 1 (oldest))
58+ BUFFER=$(fc -l -n -1 1 | percol --query "$LBUFFER")
59+ CURSOR=$#BUFFER
60+ zle -R -c
61+}
62+zle -N percol_select_history
63+bindkey -M emacs '^R' percol_select_history
64+bindkey -M viins '^R' percol_select_history
65+bindkey -M vicmd '^R' percol_select_history
6667- if which marks &> /dev/null; then
68- function percol_select_marks() {
69- BUFFER=$(marks | percol --query "$LBUFFER" | awk '{print $3}')
70- CURSOR=$#BUFFER # move cursor
71- zle -R -c # refresh
72- }
73- zle -N percol_select_marks
74- bindkey '^B' percol_select_marks
75- fi
76+if (( ${+functions[marks]} )); then
77+ function percol_select_marks() {
78+ # parse directory from marks output (markname -> path) and quote if necessary
79+ BUFFER=${(q)"$(marks | percol --query "$LBUFFER")"##*-> }
80+ CURSOR=$#BUFFER
81+ zle -R -c
82+ }
83+ zle -N percol_select_marks
84+ bindkey -M emacs '^B' percol_select_marks
85+ bindkey -M viins '^B' percol_select_marks
86+ bindkey -M vicmd '^B' percol_select_marks
87 fi