Added percol plugin
This commit is contained in:
parent
d848c94804
commit
213a01ae99
31
plugins/percol/README.md
Normal file
31
plugins/percol/README.md
Normal file
@ -0,0 +1,31 @@
|
||||
## percol
|
||||
|
||||
**Maintainer:** [@robturtle](https://github.com/robturtle)
|
||||
|
||||
It provides two functionalities that allow you search history and resume
|
||||
background jobs with interactively incremental searching utility powered by
|
||||
[Percol](https://github.com/mooz/percol).
|
||||
|
||||
### Usage
|
||||
|
||||
1. Use `Ctrl-R` to search the history.
|
||||
|
||||
![interactively search history](https://www.dropbox.com/s/2ke80q5uswz7sqf/percol.plugin1.gif?raw=1)
|
||||
|
||||
2. Use `Ctrl-Q` to resume background jobs.
|
||||
|
||||
![interactively resume background jobs](https://www.dropbox.com/s/u5t5l7jeznv06y8/percol.plugin2.gif?raw=1)
|
||||
|
||||
### Installation
|
||||
|
||||
1. [Install percol](https://github.com/mooz/percol) from pip:
|
||||
|
||||
```
|
||||
pip install percol
|
||||
```
|
||||
|
||||
2. Enable the plugin by adding it to your `plugins` definition in `~/.zshrc`:
|
||||
|
||||
```
|
||||
plugins=(percol)
|
||||
```
|
38
plugins/percol/percol.plugin.zsh
Normal file
38
plugins/percol/percol.plugin.zsh
Normal file
@ -0,0 +1,38 @@
|
||||
#!/bin/zsh
|
||||
|
||||
function exists {
|
||||
which $1 &> /dev/null
|
||||
}
|
||||
|
||||
if exists percol; then
|
||||
## Searching zsh history
|
||||
function percol_select_history() {
|
||||
local tac
|
||||
exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } }
|
||||
BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
|
||||
CURSOR=$#BUFFER # move cursor
|
||||
zle -R -c # refresh
|
||||
}
|
||||
zle -N percol_select_history
|
||||
bindkey '^R' percol_select_history
|
||||
|
||||
## use `fg 1` just like under BASH, no need to type `fg %1`
|
||||
fg() {
|
||||
if [[ $# -eq 1 && $1 = - ]]; then
|
||||
builtin fg %-
|
||||
else
|
||||
builtin fg %"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
## Interactively resume background jobs
|
||||
function percol_resume_job {
|
||||
ID=$(jobs | grep '\[\d\d*\]' | percol | sed -E 's/\[([0-9]+)\].*/\1/')
|
||||
if [[ -n ${ID} ]]; then
|
||||
fg ${ID}
|
||||
fi
|
||||
zle -R -c
|
||||
}
|
||||
zle -N percol_resume_job
|
||||
bindkey '^Q' percol_resume_job
|
||||
fi
|
Loading…
Reference in New Issue
Block a user