ac0d71467be9de2e399ef99ae58d7780e1d2ff4c

Author
当轩 <me@dangxuan.pro>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

add plugin:percol (#4582)

* add plugin:percol

* fix format

* check percol

* fix empty history in gnome terminal

Diff

 1diff --git a/plugins/percol/README.md b/plugins/percol/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..97cca68766d830412ba0f59d96a3540a79fdf990
 4--- /dev/null
 5+++ b/plugins/percol/README.md
 6@@ -0,0 +1,23 @@
 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/robbyrussell/oh-my-zsh/blob/master/plugins/jump/jump.plugin.zsh)
10+
11+### Preview
12+![Preview](http://t1.qpic.cn/mblogpic/eb1c8f9d2b9f62d19fa8/2000.jpg)
13+
14+### Requirements
15+
16+```shell
17+pip install percol
18+```
19+
20+And [jump](https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/jump/jump.plugin.zsh) for `oh-my-zsh` is a optional requirement.
21+
22+### Usage
23+
24+For default
25+
26+- `^-r` bind to `percol_select_history`.You can use it to grep your history with percol.
27+
28+- `^-b` bind to `percol_select_marks`.You can use it to grep your bookmarks with percol.
29+
30diff --git a/plugins/percol/percol.plugin.zsh b/plugins/percol/percol.plugin.zsh
31new file mode 100644
32index 0000000000000000000000000000000000000000..c6adf4e1eeff3a3c96fa68b64d6c68306aa140c6
33--- /dev/null
34+++ b/plugins/percol/percol.plugin.zsh
35@@ -0,0 +1,22 @@
36+if which percol &> /dev/null; then
37+    function percol_select_history() {
38+        local tac
39+        which gtac &> /dev/null && tac="gtac" || { which tac &> /dev/null && tac="tac" || { tac="tail -r" } }
40+        BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
41+        CURSOR=$#BUFFER
42+        zle -R -c
43+    }
44+
45+    zle -N percol_select_history
46+    bindkey '^R' percol_select_history
47+
48+    if which marks &> /dev/null; then
49+        function percol_select_marks() {
50+            BUFFER=$(marks | percol --query "$LBUFFER" | awk '{print $3}')
51+            CURSOR=$#BUFFER # move cursor
52+            zle -R -c       # refresh
53+        }
54+        zle -N percol_select_marks
55+        bindkey '^B' percol_select_marks
56+    fi
57+fi