Skip to content
Myr

key-bindings.bash

This file

Path

shell/key-bindings.bash

146 lines · 5.4 KiB · Shell

Last changed by

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

History of this file

Take it

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

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 1–13why, one step back
1# ____ ____
2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/5# /_/ /___/_/ key-bindings.bash6#7# - $FZF_TMUX_OPTS8# - $FZF_CTRL_T_COMMAND9# - $FZF_CTRL_T_OPTS10# - $FZF_CTRL_R_OPTS11# - $FZF_ALT_C_COMMAND12# - $FZF_ALT_C_OPTS13

[shell] Revert interactiveness checks for evalJunegunn Choibefore adoption152988c

line 14why, one step back
14if [[ $- =~ i ]]; then

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 15–18why, one step back
15
1617# Key bindings18# ------------

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

lines 19–27why, one step back
19
20__fzf_defaults() {21 # $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS22 # $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS23 echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"24 command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null25 echo "${FZF_DEFAULT_OPTS-} $2"26}27

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

line 28why, one step back
28__fzf_select__() {

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

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

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 32–48why, one step back
32 while read -r item; do
33 printf '%q ' "$item" # escape special chars34 done35}3637__fzfcmd() {38 [[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; } &&39 echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"40}4142fzf-file-widget() {43 local selected="$(__fzf_select__ "$@")"44 READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"45 READLINE_POINT=$(( READLINE_POINT + ${#selected} ))46}4748__fzf_cd__() {

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

line 49why, one step back
49 local dir

Add walker options and replace 'find' with the built-in walker (#3649)Junegunn Choibefore adoptiond282a16

line 50why, one step back
50 dir=$(

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

lines 51–53why, one step back
51 FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} \
52 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \53 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd)

[shell] Make ALT-C use the absolute path to the selected directory (#3688)Emilio Vesprinibefore adoption7de87a9

line 54why, one step back
54 ) && printf 'builtin cd -- %q' "$(builtin unset CDPATH && builtin cd -- "$dir" && builtin pwd)"

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 55–58why, one step back
55}
5657if command -v perl > /dev/null; then58 __fzf_history__() {

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

line 59why, one step back
59 local output script

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 60–64why, one step back
60 script='BEGIN { getc; $/ = "\n\t"; $HISTCOUNT = $ENV{last_hist} + 1 } s/^[ *]//; print $HISTCOUNT - $. . "\t$_" if !$seen{$_}++'
61 output=$(62 set +o pipefail63 builtin fc -lnr -2147483648 |64 last_hist=$(HISTTIMEFORMAT='' builtin history 1) command perl -n -l0 -e "$script" |

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

lines 65–66why, one step back
65 FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort ${FZF_CTRL_R_OPTS-} +m --read0") \
66 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 67–76why, one step back
67 ) || return
68 READLINE_LINE=${output#*$'\t'}69 if [[ -z "$READLINE_POINT" ]]; then70 echo "$READLINE_LINE"71 else72 READLINE_POINT=0x7fffffff73 fi74 }75else # awk - fallback for POSIX systems76 __fzf_history__() {

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

line 77why, one step back
77 local output script n x y z d

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 78–93why, one step back
78 if [[ -z $__fzf_awk ]]; then
79 __fzf_awk=awk80 # choose the faster mawk if: it's installed && build date >= 20230322 && version >= 1.3.481 IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null)82 [[ $n == mawk ]] && (( d >= 20230302 && (x *1000 +y) *1000 +z >= 1003004 )) && __fzf_awk=mawk83 fi84 [[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries85 script='function P(b) { ++n; sub(/^[ *]/, "", b); if (!seen[b]++) { printf "%d\t%s%c", '$((BASH_REMATCH + 1))' - n, b, 0 } }86 NR==1 { b = substr($0, 2); next }87 /^\t/ { P(b); b = substr($0, 2); next }88 { b = b RS $0 }89 END { if (NR) P(b) }'90 output=$(91 set +o pipefail92 builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )*93 command $__fzf_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )*

Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion (#3742)Junegunn Choibefore adoptionf864f8b

lines 94–95why, one step back
94 FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort ${FZF_CTRL_R_OPTS-} +m --read0") \
95 FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 96–114why, one step back
96 ) || return
97 READLINE_LINE=${output#*$'\t'}98 if [[ -z "$READLINE_POINT" ]]; then99 echo "$READLINE_LINE"100 else101 READLINE_POINT=0x7fffffff102 fi103 }104fi105106# Required to refresh the prompt after fzf107bind -m emacs-standard '"\er": redraw-current-line'108109bind -m vi-command '"\C-z": emacs-editing-mode'110bind -m vi-insert '"\C-z": emacs-editing-mode'111bind -m emacs-standard '"\C-z": vi-editing-mode'112113if (( BASH_VERSINFO[0] < 4 )); then114 # CTRL-T - Paste the selected file path into the command line

Make it possible to disable `Ctrl+T` / `Alt+C` / completions (#3678)Eli Barzilaybefore adoption88f4c16

lines 115–119why, one step back
115 if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then
116 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"'117 bind -m vi-command '"\C-t": "\C-z\C-t\C-z"'118 bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"'119 fi

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 120–126why, one step back
120
121 # CTRL-R - Paste the selected command from history into the command line122 bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er"'123 bind -m vi-command '"\C-r": "\C-z\C-r\C-z"'124 bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"'125else126 # CTRL-T - Paste the selected file path into the command line

Make it possible to disable `Ctrl+T` / `Alt+C` / completions (#3678)Eli Barzilaybefore adoption88f4c16

lines 127–131why, one step back
127 if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then
128 bind -m emacs-standard -x '"\C-t": fzf-file-widget'129 bind -m vi-command -x '"\C-t": fzf-file-widget'130 bind -m vi-insert -x '"\C-t": fzf-file-widget'131 fi

Add {fzf:prompt} placeholder expressionJunegunn Choibefore adoption5d36018

lines 132–139why, one step back
132
133 # CTRL-R - Paste the selected command from history into the command line134 bind -m emacs-standard -x '"\C-r": __fzf_history__'135 bind -m vi-command -x '"\C-r": __fzf_history__'136 bind -m vi-insert -x '"\C-r": __fzf_history__'137fi138139# ALT-C - cd into the selected directory

Make it possible to disable `Ctrl+T` / `Alt+C` / completions (#3678)Eli Barzilaybefore adoption88f4c16

lines 140–143why, one step back
140if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then
141 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"'142 bind -m vi-command '"\ec": "\C-z\ec\C-z"'143 bind -m vi-insert '"\ec": "\C-z\ec\C-z"'

[shell] Revert interactiveness checks for evalJunegunn Choibefore adoption152988c

lines 144–145why, one step back
144fi
145

Make it possible to disable `Ctrl+T` / `Alt+C` / completions (#3678)Eli Barzilaybefore adoption88f4c16

line 146why, one step back
146fi