mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-22 04:51:12 +02:00
Added percol plugin
This commit is contained in:
parent
d848c94804
commit
213a01ae99
2 changed files with 69 additions and 0 deletions
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…
Add table
Add a link
Reference in a new issue