Skip to content
Myr

key-bindings.bash

This file

Path

shell/key-bindings.bash

121 lines · 4.5 KiB · Shell

Last changed by

[shell] Enable sorting by default in CTRL-RJunegunn Choibefore adoptionc387689

History of this file

Take it

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

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 1–3why, one step back
1# Key bindings
2# ------------3__fzf_select__() {

Exclude sysfs in find commandsJunegunn Choibefore adoption11407bf

line 4why, one step back
4 local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 5–48why, one step back
5 -o -type f -print \
6 -o -type d -print \7 -o -type l -print 2> /dev/null | cut -b3-"}"8 eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" fzf -m "$@" | while read -r item; do9 printf '%q ' "$item"10 done11 echo12}1314if [[ $- =~ i ]]; then1516__fzf_use_tmux__() {17 [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]18}1920__fzfcmd() {21 __fzf_use_tmux__ &&22 echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"23}2425__fzf_select_tmux__() {26 local height27 height=${FZF_TMUX_HEIGHT:-40%}28 if [[ $height =~ %$ ]]; then29 height="-p ${height%\%}"30 else31 height="-l $height"32 fi3334 tmux split-window $height "cd $(printf %q "$PWD"); FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS") PATH=$(printf %q "$PATH") FZF_CTRL_T_COMMAND=$(printf %q "$FZF_CTRL_T_COMMAND") FZF_CTRL_T_OPTS=$(printf %q "$FZF_CTRL_T_OPTS") bash -c 'source \"${BASH_SOURCE[0]}\"; RESULT=\"\$(__fzf_select__ --no-height)\"; tmux setb -b fzf \"\$RESULT\" \\; pasteb -b fzf -t $TMUX_PANE \\; deleteb -b fzf || tmux send-keys -t $TMUX_PANE \"\$RESULT\"'"35}3637fzf-file-widget() {38 if __fzf_use_tmux__; then39 __fzf_select_tmux__40 else41 local selected="$(__fzf_select__)"42 READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"43 READLINE_POINT=$(( READLINE_POINT + ${#selected} ))44 fi45}4647__fzf_cd__() {48 local cmd dir

Exclude sysfs in find commandsJunegunn Choibefore adoption11407bf

line 49why, one step back
49 cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \

[shell] Replace `sed` with `-mindepth 1` and `cut` (#844)Pierre Neidhardtbefore adoptionce43ea9

line 50why, one step back
50 -o -type d -print 2> /dev/null | cut -b3-"}"

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 51–58why, one step back
51 dir=$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m) && printf 'cd %q' "$dir"
52}5354__fzf_history__() (55 local line56 shopt -u nocaseglob nocasematch57 line=$(58 HISTTIMEFORMAT= history |

[shell] Enable sorting by default in CTRL-RJunegunn Choibefore adoptionc387689

line 59why, one step back
59 FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m" $(__fzfcmd) |

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 60–121why, one step back
60 command grep '^ *[0-9]') &&
61 if [[ $- =~ H ]]; then62 sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line"63 else64 sed 's/^ *\([0-9]*\)\** *//' <<< "$line"65 fi66)6768if [[ ! -o vi ]]; then69 # Required to refresh the prompt after fzf70 bind '"\er": redraw-current-line'71 bind '"\e^": history-expand-line'7273 # CTRL-T - Paste the selected file path into the command line74 if [ $BASH_VERSINFO -gt 3 ]; then75 bind -x '"\C-t": "fzf-file-widget"'76 elif __fzf_use_tmux__; then77 bind '"\C-t": " \C-u \C-a\C-k`__fzf_select_tmux__`\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"'78 else79 bind '"\C-t": " \C-u \C-a\C-k`__fzf_select__`\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"'80 fi8182 # CTRL-R - Paste the selected command from history into the command line83 bind '"\C-r": " \C-e\C-u`__fzf_history__`\e\C-e\e^\er"'8485 # ALT-C - cd into the selected directory86 bind '"\ec": " \C-e\C-u`__fzf_cd__`\e\C-e\er\C-m"'87else88 # We'd usually use "\e" to enter vi-movement-mode so we can do our magic,89 # but this incurs a very noticeable delay of a half second or so,90 # because many other commands start with "\e".91 # Instead, we bind an unused key, "\C-x\C-a",92 # to also enter vi-movement-mode,93 # and then use that thereafter.94 # (We imagine that "\C-x\C-a" is relatively unlikely to be in use.)95 bind '"\C-x\C-a": vi-movement-mode'9697 bind '"\C-x\C-e": shell-expand-line'98 bind '"\C-x\C-r": redraw-current-line'99 bind '"\C-x^": history-expand-line'100101 # CTRL-T - Paste the selected file path into the command line102 # - FIXME: Selected items are attached to the end regardless of cursor position103 if [ $BASH_VERSINFO -gt 3 ]; then104 bind -x '"\C-t": "fzf-file-widget"'105 elif __fzf_use_tmux__; then106 bind '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select_tmux__`\C-x\C-e\C-x\C-a0P$xa"'107 else108 bind '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select__`\C-x\C-e\C-x\C-a0Px$a \C-x\C-r\C-x\C-axa "'109 fi110 bind -m vi-command '"\C-t": "i\C-t"'111112 # CTRL-R - Paste the selected command from history into the command line113 bind '"\C-r": "\C-x\C-addi`__fzf_history__`\C-x\C-e\C-x^\C-x\C-a$a\C-x\C-r"'114 bind -m vi-command '"\C-r": "i\C-r"'115116 # ALT-C - cd into the selected directory117 bind '"\ec": "\C-x\C-addi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"'118 bind -m vi-command '"\ec": "ddi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"'119fi120121fi