Skip to content
Myr

key-bindings.bash

This file

Path

shell/key-bindings.bash

174 lines · 6.4 KiB · Shell

Last changed by

[bash,zsh] Fix the version check for mawk (#4574)Koichi Murasebefore adoption5cb6957

History of this file

Take it

The walk stopped after 200 commits: lines older than d22e75d point at it.

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 1–9why, one step back
1# ____ ____
2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/5# /_/ /___/_/ key-bindings.bash6#7# - $FZF_TMUX_OPTS8# - $FZF_CTRL_T_COMMAND9# - $FZF_CTRL_T_OPTS

feat: Allow disabling Ctrl-R binding in shell integration (#4535)Jacobo de Verabefore adoption0e9026b

line 10why, one step back
10# - $FZF_CTRL_R_COMMAND

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 11–20why, one step back
11# - $FZF_CTRL_R_OPTS
12# - $FZF_ALT_C_COMMAND13# - $FZF_ALT_C_OPTS1415if [[ $- =~ i ]]; then161718# Key bindings19# ------------20

make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4

line 21why, one step back
21#----BEGIN shfmt

[bash,zsh] Separate common functions into "shell/common.sh"Koichi Murasebefore adoptionbfa287b

lines 22–23why, one step back
22#----BEGIN INCLUDE common.sh
23# NOTE: Do not directly edit this section, which is copied from "common.sh".

make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4

line 24why, one step back
24# To modify it, one can edit "common.sh" and run "./update.sh" to apply

[bash,zsh] Separate common functions into "shell/common.sh"Koichi Murasebefore adoptionbfa287b

lines 25–26why, one step back
25# the changes. See code comments in "common.sh" for the implementation details.
26

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

line 27why, one step back
27__fzf_defaults() {

[bash,zsh] Separate common functions into "shell/common.sh"Koichi Murasebefore adoptionbfa287b

line 28why, one step back
28 printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

line 29why, one step back
29 command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null

[bash,zsh] Separate common functions into "shell/common.sh"Koichi Murasebefore adoptionbfa287b

line 30why, one step back
30 printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 31–32why, one step back
31}
32

[bash,zsh] Work around a quirk of macOS awkKoichi Murasebefore adoption09194c2

lines 33–35why, one step back
33__fzf_exec_awk() {
34 if [[ -z ${__fzf_awk-} ]]; then35 __fzf_awk=awk

[bash,zsh] Work around Solaris awk, which is non-standardKoichi Murasebefore adoptionc166eab

lines 36–37why, one step back
36 if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
37 __fzf_awk=/usr/xpg4/bin/awk

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 38why, one step back
38 elif command -v mawk > /dev/null 2>&1; then

[bash,zsh] Work around Solaris awk, which is non-standardKoichi Murasebefore adoptionc166eab

line 39why, one step back
39 local n x y z d

fix(shell): check for mawk existence before version check (#4468)LangLangBartbefore adoption354d046

line 40why, one step back
40 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)

[bash,zsh] Fix the version check for mawk (#4574)Koichi Murasebefore adoption5cb6957

lines 41–44why, one step back
41 [[ $n == mawk ]] &&
42 (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&43 ((d >= 20230302)) 2> /dev/null &&44 __fzf_awk=mawk

[bash,zsh] Work around Solaris awk, which is non-standardKoichi Murasebefore adoptionc166eab

line 45why, one step back
45 fi

[bash,zsh] Work around a quirk of macOS awkKoichi Murasebefore adoption09194c2

lines 46–48why, one step back
46 fi
47 LC_ALL=C exec "$__fzf_awk" "$@"48}

[bash,zsh] Separate common functions into "shell/common.sh"Koichi Murasebefore adoptionbfa287b

line 49why, one step back
49#----END INCLUDE

[bash,zsh] Work around a quirk of macOS awkKoichi Murasebefore adoption09194c2

line 50why, one step back
50

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 51–52why, one step back
51__fzf_select__() {
52 FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 53–54why, one step back
53 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \
54 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" |

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

line 55why, one step back
55 while read -r item; do

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 56why, one step back
56 printf '%q ' "$item" # escape special chars

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 57–60why, one step back
57 done
58}5960__fzfcmd() {

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 61why, one step back
61 [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; } &&

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 62–66why, one step back
62 echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
63}6465fzf-file-widget() {66 local selected="$(__fzf_select__ "$@")"

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 67–68why, one step back
67 READLINE_LINE="${READLINE_LINE:0:READLINE_POINT}$selected${READLINE_LINE:READLINE_POINT}"
68 READLINE_POINT=$((READLINE_POINT + ${#selected}))

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 69–74why, one step back
69}
7071__fzf_cd__() {72 local dir73 dir=$(74 FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} \

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 75–76why, one step back
75 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \
76 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd)

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 77–87why, one step back
77 ) && printf 'builtin cd -- %q' "$(builtin unset CDPATH && builtin cd -- "$dir" && builtin pwd)"
78}7980if command -v perl > /dev/null; then81 __fzf_history__() {82 local output script83 script='BEGIN { getc; $/ = "\n\t"; $HISTCOUNT = $ENV{last_hist} + 1 } s/^[ *]//; s/\n/\n\t/gm; print $HISTCOUNT - $. . "\t$_" if !$seen{$_}++'84 output=$(85 set +o pipefail86 builtin fc -lnr -2147483648 |87 last_hist=$(HISTTIMEFORMAT='' builtin history 1) command perl -n -l0 -e "$script" |

CTRL-R: Bind ALT-R to toggle-rawJunegunn Choibefore adoptione1de29b

line 88why, one step back
88 FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,alt-r:toggle-raw --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 89–91why, one step back
89 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"
90 ) || return91 READLINE_LINE=$(command perl -pe 's/^\d*\t//' <<< "$output")

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 92why, one step back
92 if [[ -z $READLINE_POINT ]]; then

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 93–99why, one step back
93 echo "$READLINE_LINE"
94 else95 READLINE_POINT=0x7fffffff96 fi97 }98else # awk - fallback for POSIX systems99 __fzf_history__() {

[bash,zsh] Work around a quirk of macOS awkKoichi Murasebefore adoption09194c2

line 100why, one step back
100 local output script

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 101why, one step back
101 [[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 102–108why, one step back
102 script='function P(b) { ++n; sub(/^[ *]/, "", b); if (!seen[b]++) { printf "%d\t%s%c", '$((BASH_REMATCH + 1))' - n, b, 0 } }
103 NR==1 { b = substr($0, 2); next }104 /^\t/ { P(b); b = substr($0, 2); next }105 { b = b RS $0 }106 END { if (NR) P(b) }'107 output=$(108 set +o pipefail

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

lines 109–110why, one step back
109 builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )*
110 __fzf_exec_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )*

CTRL-R: Bind ALT-R to toggle-rawJunegunn Choibefore adoptione1de29b

line 111why, one step back
111 FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,alt-r:toggle-raw --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 112–114why, one step back
112 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"
113 ) || return114 READLINE_LINE=${output#*$'\t'}

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 115why, one step back
115 if [[ -z $READLINE_POINT ]]; then

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 116–129why, one step back
116 echo "$READLINE_LINE"
117 else118 READLINE_POINT=0x7fffffff119 fi120 }121fi122123# Required to refresh the prompt after fzf124bind -m emacs-standard '"\er": redraw-current-line'125126bind -m vi-command '"\C-z": emacs-editing-mode'127bind -m vi-insert '"\C-z": emacs-editing-mode'128bind -m emacs-standard '"\C-z": vi-editing-mode'129

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 130why, one step back
130if ((BASH_VERSINFO[0] < 4)); then

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

line 131why, one step back
131 # CTRL-T - Paste the selected file path into the command line

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 132why, one step back
132 if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; then

[bash 3] Fix CTRL-T and ALT-C to preserve the last yank (#4496)xtybefore adoptionf9d7877

line 133why, one step back
133 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-_"'

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 134–138why, one step back
134 bind -m vi-command '"\C-t": "\C-z\C-t\C-z"'
135 bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"'136 fi137138 # CTRL-R - Paste the selected command from history into the command line

feat: Allow disabling Ctrl-R binding in shell integration (#4535)Jacobo de Verabefore adoption0e9026b

lines 139–146why, one step back
139 if [[ ${FZF_CTRL_R_COMMAND-x} != "" ]]; then
140 if [[ -n ${FZF_CTRL_R_COMMAND-} ]]; then141 echo "warning: FZF_CTRL_R_COMMAND is set to a custom command, but custom commands are not yet supported for CTRL-R" >&2142 fi143 bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er"'144 bind -m vi-command '"\C-r": "\C-z\C-r\C-z"'145 bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"'146 fi

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 147–148why, one step back
147else
148 # CTRL-T - Paste the selected file path into the command line

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 149why, one step back
149 if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; then

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 150–155why, one step back
150 bind -m emacs-standard -x '"\C-t": fzf-file-widget'
151 bind -m vi-command -x '"\C-t": fzf-file-widget'152 bind -m vi-insert -x '"\C-t": fzf-file-widget'153 fi154155 # CTRL-R - Paste the selected command from history into the command line

feat: Allow disabling Ctrl-R binding in shell integration (#4535)Jacobo de Verabefore adoption0e9026b

lines 156–163why, one step back
156 if [[ ${FZF_CTRL_R_COMMAND-x} != "" ]]; then
157 if [[ -n ${FZF_CTRL_R_COMMAND-} ]]; then158 echo "warning: FZF_CTRL_R_COMMAND is set to a custom command, but custom commands are not yet supported for CTRL-R" >&2159 fi160 bind -m emacs-standard -x '"\C-r": __fzf_history__'161 bind -m vi-command -x '"\C-r": __fzf_history__'162 bind -m vi-insert -x '"\C-r": __fzf_history__'163 fi

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 164–166why, one step back
164fi
165166# ALT-C - cd into the selected directory

Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315

line 167why, one step back
167if [[ ${FZF_ALT_C_COMMAND-x} != "" ]]; then

[bash 3] Fix CTRL-T and ALT-C to preserve the last yank (#4496)xtybefore adoptionf9d7877

line 168why, one step back
168 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-_"'

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 169–171why, one step back
169 bind -m vi-command '"\ec": "\C-z\ec\C-z"'
170 bind -m vi-insert '"\ec": "\C-z\ec\C-z"'171fi

make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4

line 172why, one step back
172#----END shfmt

Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d

lines 173–174why, one step back
173
174fi