refactor(percol): fix style, bind keys for vi-mode and remove dependencies

parent b2f35a7b
## percol # percol
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) Provides some useful function to make [percol](https://github.com/mooz/percol) work with zsh history and
the [jump plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/jump), optionally.
### Requirements To use it, add `percol` to the plugins array in your zshrc:
```shell ```zsh
pip install percol plugins=(... percol)
``` ```
And [jump](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/jump/jump.plugin.zsh) for `oh-my-zsh` is a optional requirement. ## Requirements
### Usage - `percol`: install with `pip install percol`.
For default - (_Optional_) [`jump`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/jump) plugin: needs to be
enabled before the `percol` plugin.
- `^-r` bind to `percol_select_history`.You can use it to grep your history with percol. ## Usage
- `^-b` bind to `percol_select_marks`.You can use it to grep your bookmarks with percol. - <kbd>CTRL-R</kbd> (bound to `percol_select_history`): you can use it to grep your history with percol.
- <kbd>CTRL-B</kbd> (bound to `percol_select_marks`): you can use it to grep your jump bookmarks with percol.
if which percol &> /dev/null; then (( ${+commands[percol]} )) || return
function percol_select_history() {
local tac function percol_select_history() {
which gtac &> /dev/null && tac="gtac" || { which tac &> /dev/null && tac="tac" || { tac="tail -r" } } # print history in reverse order (from -1 (latest) to 1 (oldest))
BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER") BUFFER=$(fc -l -n -1 1 | percol --query "$LBUFFER")
CURSOR=$#BUFFER CURSOR=$#BUFFER
zle -R -c zle -R -c
} }
zle -N percol_select_history
zle -N percol_select_history bindkey -M emacs '^R' percol_select_history
bindkey '^R' percol_select_history bindkey -M viins '^R' percol_select_history
bindkey -M vicmd '^R' percol_select_history
if which marks &> /dev/null; then if (( ${+functions[marks]} )); then
function percol_select_marks() { function percol_select_marks() {
BUFFER=$(marks | percol --query "$LBUFFER" | awk '{print $3}') # parse directory from marks output (markname -> path) and quote if necessary
CURSOR=$#BUFFER # move cursor BUFFER=${(q)"$(marks | percol --query "$LBUFFER")"##*-> }
zle -R -c # refresh CURSOR=$#BUFFER
zle -R -c
} }
zle -N percol_select_marks zle -N percol_select_marks
bindkey '^B' percol_select_marks bindkey -M emacs '^B' percol_select_marks
fi bindkey -M viins '^B' percol_select_marks
bindkey -M vicmd '^B' percol_select_marks
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment