Merge pull request #1956 from gaelicWizard/plugin-percol

plugin/percol `shellcheck`
pull/1885/head
Noah Gorny 2021-09-28 15:06:33 +03:00 committed by GitHub
commit 05aac8ef39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 19 deletions

View File

@ -93,6 +93,7 @@ plugins/available/hub.plugin.bash
plugins/available/jump.plugin.bash plugins/available/jump.plugin.bash
plugins/available/node.plugin.bash plugins/available/node.plugin.bash
plugins/available/nodenv.plugin.bash plugins/available/nodenv.plugin.bash
plugins/available/percol.plugin.bash
plugins/available/plenv.plugin.bash plugins/available/plenv.plugin.bash
plugins/available/pyenv.plugin.bash plugins/available/pyenv.plugin.bash
plugins/available/rbenv.plugin.bash plugins/available/rbenv.plugin.bash

View File

@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'Search&Select history with percol' about-plugin 'Search&Select history with percol'
@ -12,24 +13,20 @@ about-plugin 'Search&Select history with percol'
# Usage # Usage
## C-r to search&select from history ## C-r to search&select from history
_replace_by_history() { _command_exists percol || return
if command -v tac>/dev/null; then
alias _tac=tac if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then
else _log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin."
alias _tac="tail -r" _log_warning "Your current Bash version is $BASH_VERSION."
fi return
local l=$(HISTTIMEFORMAT= history | _tac | sed -e 's/^\ *[0-9]*\ *//' | percol --query "$READLINE_LINE") fi
READLINE_LINE="$l"
function _replace_by_history() {
local HISTTIMEFORMAT= # Ensure we can parse history properly
#TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}"
local l
l="$(history | tail -r | sed -e 's/^\ *[0-9]*\ *//' | percol --query "${READLINE_LINE:-}")"
READLINE_LINE="${l}"
READLINE_POINT=${#l} READLINE_POINT=${#l}
} }
bind -x '"\C-r": _replace_by_history'
if command -v percol>/dev/null; then
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'
fi
fi