diff options
Diffstat (limited to 'shell/key-bindings.bash')
| -rw-r--r-- | shell/key-bindings.bash | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index 500591bc..139476df 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -34,10 +34,10 @@ __fzf_exec_awk() { __fzf_awk=awk if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then __fzf_awk=/usr/xpg4/bin/awk - elif command -v mawk >/dev/null 2>&1; then + elif command -v mawk > /dev/null 2>&1; then local n x y z d IFS=' .' read -r 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 + [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk fi fi LC_ALL=C exec "$__fzf_awk" "$@" @@ -46,30 +46,30 @@ __fzf_exec_awk() { __fzf_select__() { FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \ - FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \ - FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" | + FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \ + FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" | while read -r item; do - printf '%q ' "$item" # escape special chars + printf '%q ' "$item" # escape special chars done } __fzfcmd() { - [[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; } && + [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; } && echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf" } fzf-file-widget() { local selected="$(__fzf_select__ "$@")" - READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}" - READLINE_POINT=$(( READLINE_POINT + ${#selected} )) + READLINE_LINE="${READLINE_LINE:0:READLINE_POINT}$selected${READLINE_LINE:READLINE_POINT}" + READLINE_POINT=$((READLINE_POINT + ${#selected})) } __fzf_cd__() { local dir dir=$( FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} \ - FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \ - FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) + FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \ + FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) ) && printf 'builtin cd -- %q' "$(builtin unset CDPATH && builtin cd -- "$dir" && builtin pwd)" } @@ -85,7 +85,7 @@ if command -v perl > /dev/null; then FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE" ) || return READLINE_LINE=$(command perl -pe 's/^\d*\t//' <<< "$output") - if [[ -z "$READLINE_POINT" ]]; then + if [[ -z $READLINE_POINT ]]; then echo "$READLINE_LINE" else READLINE_POINT=0x7fffffff @@ -94,7 +94,7 @@ if command -v perl > /dev/null; then else # awk - fallback for POSIX systems __fzf_history__() { local output script - [[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries + [[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries script='function P(b) { ++n; sub(/^[ *]/, "", b); if (!seen[b]++) { printf "%d\t%s%c", '$((BASH_REMATCH + 1))' - n, b, 0 } } NR==1 { b = substr($0, 2); next } /^\t/ { P(b); b = substr($0, 2); next } @@ -102,13 +102,13 @@ else # awk - fallback for POSIX systems END { if (NR) P(b) }' output=$( set +o pipefail - builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )* - __fzf_exec_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )* + builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )* + __fzf_exec_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )* FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \ FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE" ) || return READLINE_LINE=${output#*$'\t'} - if [[ -z "$READLINE_POINT" ]]; then + if [[ -z $READLINE_POINT ]]; then echo "$READLINE_LINE" else READLINE_POINT=0x7fffffff @@ -123,9 +123,9 @@ bind -m vi-command '"\C-z": emacs-editing-mode' bind -m vi-insert '"\C-z": emacs-editing-mode' bind -m emacs-standard '"\C-z": vi-editing-mode' -if (( BASH_VERSINFO[0] < 4 )); then +if ((BASH_VERSINFO[0] < 4)); then # CTRL-T - Paste the selected file path into the command line - if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then + if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; then bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f\C-y\ey\C-_"' bind -m vi-command '"\C-t": "\C-z\C-t\C-z"' bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"' @@ -137,7 +137,7 @@ if (( BASH_VERSINFO[0] < 4 )); then bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"' else # CTRL-T - Paste the selected file path into the command line - if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then + if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; then bind -m emacs-standard -x '"\C-t": fzf-file-widget' bind -m vi-command -x '"\C-t": fzf-file-widget' bind -m vi-insert -x '"\C-t": fzf-file-widget' @@ -150,7 +150,7 @@ else fi # ALT-C - cd into the selected directory -if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then +if [[ ${FZF_ALT_C_COMMAND-x} != "" ]]; then bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d\C-y\ey\C-_"' bind -m vi-command '"\ec": "\C-z\ec\C-z"' bind -m vi-insert '"\ec": "\C-z\ec\C-z"' |
