summaryrefslogtreecommitdiffstats
path: root/shell/key-bindings.bash
diff options
context:
space:
mode:
Diffstat (limited to 'shell/key-bindings.bash')
-rw-r--r--shell/key-bindings.bash16
1 files changed, 7 insertions, 9 deletions
diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash
index 8654a6f2..398f66e4 100644
--- a/shell/key-bindings.bash
+++ b/shell/key-bindings.bash
@@ -56,7 +56,7 @@ if command -v perl > /dev/null; then
output=$(
set +o pipefail
builtin fc -lnr -2147483648 |
- last_hist=$(HISTTIMEFORMAT='' builtin history 1) perl -n -l0 -e "$script" |
+ last_hist=$(HISTTIMEFORMAT='' builtin history 1) command perl -n -l0 -e "$script" |
FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) --query "$READLINE_LINE"
) || return
READLINE_LINE=${output#*$'\t'}
@@ -66,16 +66,14 @@ if command -v perl > /dev/null; then
READLINE_POINT=0x7fffffff
fi
}
-else # awk
+else # awk - fallback for POSIX systems
__fzf_history__() {
- local output opts script
+ local output opts script n x y z d
if [[ -z $__fzf_awk ]]; then
__fzf_awk=awk
- # if installed, mawk is faster
- command -v mawk > /dev/null &&
- mawk --version | # at least 1.3.4
- awk 'NR == 1 { split($2, a, "."); v=(a[1]*1000000+ a[2]*1000+ a[3]*1); exit !(v >= 1003004) }' &&
- __fzf_awk=mawk
+ # choose the faster mawk if: it's installed && build date >= 20230322 && version >= 1.3.4
+ IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null)
+ [[ $n == mawk ]] && (( d >= 20230302 && (x *1000 +y) *1000 +z >= 1003004 )) && __fzf_awk=mawk
fi
opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} -n2..,.. --scheme=history --bind=ctrl-r:toggle-sort ${FZF_CTRL_R_OPTS-} +m --read0"
[[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries
@@ -87,7 +85,7 @@ else # awk
output=$(
set +o pipefail
builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )*
- $__fzf_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )*
+ command $__fzf_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )*
FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) --query "$READLINE_LINE"
) || return
READLINE_LINE=${output#*$'\t'}