Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin/percol shellcheck #1956

Merged
merged 3 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ plugins/available/hub.plugin.bash
plugins/available/jump.plugin.bash
plugins/available/node.plugin.bash
plugins/available/nodenv.plugin.bash
plugins/available/percol.plugin.bash
plugins/available/plenv.plugin.bash
plugins/available/pyenv.plugin.bash
plugins/available/rbenv.plugin.bash
Expand Down
35 changes: 16 additions & 19 deletions plugins/available/percol.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'Search&Select history with percol'

Expand All @@ -12,24 +13,20 @@ about-plugin 'Search&Select history with percol'
# Usage
## C-r to search&select from history

_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}
}

_command_exists percol || return

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
if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then
_log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin."
_log_warning "Your current Bash version is $BASH_VERSION."
return
fi

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}
}
bind -x '"\C-r": _replace_by_history'