Files
bash-it/plugins/available/percol.plugin.bash
Adam Wallis 3651a31c5e Fixes: 659ecd0388 plugins: percol: Check for alias zz before unalias
The original patch (659ecd0388)
unaliases the percol alias, however, does not validate if the alias
is already defined. This leads to the following message that is shown
everytime a new bash session is spawned where this variable is not
defined when the percol plugin is enabled.

bash: unalias: zz: not found
2018-01-10 19:58:29 -05:00

50 lines
1.4 KiB
Bash

cite about-plugin
about-plugin 'Search&Select history and fasd with percol'
# Notice
## You have to upgrade bash to bash 4.x on Mac OS X.
## http://stackoverflow.com/questions/16416195/how-do-i-upgrade-bash-in-mac-osx-mountain-lion-and-set-it-the-correct-path
# Install
## (sudo) pip install percol
## bash-it enable percol
## optional: bash-it enable fasd
# Usage
## C-r to search&select from history
## zz to search&select from fasd
_replace_by_history() {
if command -v tac>/dev/null; then
alias _tac=tac
else
alias _tac="tail -r"
fi
local l=$(HISTTIMEFORMAT= history | _tac | sed -e 's/^\ *[0-9]*\ *//' | percol --query "$READLINE_LINE")
READLINE_LINE="$l"
READLINE_POINT=${#l}
}
if command -v percol>/dev/null; then
local current_version=${BASH_VERSION%%[^0-9]*}
if [ $current_version -lt 4 ]; then
echo -e "\033[91mWarning: You have to upgrade Bash to Bash v4.x to use the 'percol' plugin.\033[m"
echo -e "\033[91m Your current Bash version is $BASH_VERSION.\033[m"
else
bind -x '"\C-r": _replace_by_history'
# bind zz to percol if fasd enable
if [[ $(type -t zz) == 'alias' ]]; then
unalias zz
fi
if command -v fasd>/dev/null; then
function zz() {
local l=$(fasd -d | awk '{print $2}' | percol)
cd $l
}
fi
fi
fi