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 fileTake 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 back1# ____ ____2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/5# /_/ /___/_/ key-bindings.bash6#7# - $FZF_TMUX_OPTS8# - $FZF_CTRL_T_COMMAND9# - $FZF_CTRL_T_OPTSfeat: Allow disabling Ctrl-R binding in shell integration (#4535)Jacobo de Verabefore adoption0e9026b
line 10why, one step back10# - $FZF_CTRL_R_COMMANDDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 11–20why, one step back11# - $FZF_CTRL_R_OPTS12# - $FZF_ALT_C_COMMAND13# - $FZF_ALT_C_OPTS1415if [[ $- =~ i ]]; then161718# Key bindings19# ------------20make lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4
line 21why, one step back21#----BEGIN shfmt[bash,zsh] Separate common functions into "shell/common.sh"Koichi Murasebefore adoptionbfa287b
lines 22–23why, one step back22#----BEGIN INCLUDE common.sh23# 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 back24# 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 back25# the changes. See code comments in "common.sh" for the implementation details.26Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
line 27why, one step back27__fzf_defaults() {[bash,zsh] Separate common functions into "shell/common.sh"Koichi Murasebefore adoptionbfa287b
line 28why, one step back28 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 back29 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 back30 printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 31–32why, one step back31}32[bash,zsh] Work around a quirk of macOS awkKoichi Murasebefore adoption09194c2
lines 33–35why, one step back33__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 back36 if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then37 __fzf_awk=/usr/xpg4/bin/awkApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 38why, one step back38 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 back39 local n x y z dfix(shell): check for mawk existence before version check (#4468)LangLangBartbefore adoption354d046
line 40why, one step back40 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 back41 [[ $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 back45 fi[bash,zsh] Work around a quirk of macOS awkKoichi Murasebefore adoption09194c2
lines 46–48why, one step back46 fi47 LC_ALL=C exec "$__fzf_awk" "$@"48}[bash,zsh] Separate common functions into "shell/common.sh"Koichi Murasebefore adoptionbfa287b
line 49why, one step back49#----END INCLUDE[bash,zsh] Work around a quirk of macOS awkKoichi Murasebefore adoption09194c2
line 50why, one step back50Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 51–52why, one step back51__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 back53 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 back55 while read -r item; doApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 56why, one step back56 printf '%q ' "$item" # escape special charsDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 57–60why, one step back57 done58}5960__fzfcmd() {Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 61why, one step back61 [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; } &&Disable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 62–66why, one step back62 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 back67 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 back69}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 back75 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 back77 ) && 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 back88 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 back89 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 back92 if [[ -z $READLINE_POINT ]]; thenDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 93–99why, one step back93 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 back100 local output scriptApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 101why, one step back101 [[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entriesDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 102–108why, one step back102 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 pipefailApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
lines 109–110why, one step back109 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 back111 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 back112 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 back115 if [[ -z $READLINE_POINT ]]; thenDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 116–129why, one step back116 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'129Apply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 130why, one step back130if ((BASH_VERSINFO[0] < 4)); thenDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
line 131why, one step back131 # CTRL-T - Paste the selected file path into the command lineApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 132why, one step back132 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 back133 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 back134 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 linefeat: Allow disabling Ctrl-R binding in shell integration (#4535)Jacobo de Verabefore adoption0e9026b
lines 139–146why, one step back139 if [[ ${FZF_CTRL_R_COMMAND-x} != "" ]]; then140 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 fiDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 147–148why, one step back147else148 # CTRL-T - Paste the selected file path into the command lineApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 149why, one step back149 if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; thenDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 150–155why, one step back150 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 linefeat: Allow disabling Ctrl-R binding in shell integration (#4535)Jacobo de Verabefore adoption0e9026b
lines 156–163why, one step back156 if [[ ${FZF_CTRL_R_COMMAND-x} != "" ]]; then157 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 fiDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 164–166why, one step back164fi165166# ALT-C - cd into the selected directoryApply shfmt to bash script files (make fmt)Junegunn Choibefore adoptione8cb315
line 167why, one step back167if [[ ${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 back168 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 back169 bind -m vi-command '"\ec": "\C-z\ec\C-z"'170 bind -m vi-insert '"\ec": "\C-z\ec\C-z"'171fimake lint: Perform bash script lintingJunegunn Choibefore adoptionf0c4ee4
line 172why, one step back172#----END shfmtDisable bracketed paste mode on exitJunegunn Choibefore adoptiond22e75d
lines 173–174why, one step back173174fi