key-bindings.fish
This file
Path
shell/key-bindings.fish
223 lines · 8.8 KiB
Last changed by
fish: Improve custom CTRL-T command execution (#4909)bitraidbefore adoptionad151d8
History of this fileTake it
The walk stopped after 200 commits: lines older than 76efddd point at it.
bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 1–17why, one step back1# ____ ____2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/5# /_/ /___/_/ key-bindings.fish6#7# - $FZF_CTRL_T_COMMAND8# - $FZF_CTRL_T_OPTS9# - $FZF_CTRL_R_COMMAND10# - $FZF_CTRL_R_OPTS11# - $FZF_ALT_C_COMMAND12# - $FZF_ALT_C_OPTS1314# Key bindings15# ------------16function fzf_key_bindings17fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
lines 18–22why, one step back18 # The oldest supported fish version is 3.4.0. For this message being able to be19 # displayed on older versions, the command substitution syntax $() should not20 # be used anywhere in the script, otherwise the source command will fail.21 if string match -qr -- '^[12]\\.|^3\\.[0-3]' $version22 echo "fzf key bindings script requires fish version 3.4.0 or newer." >&2bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 23why, one step back23 return 1fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
line 24why, one step back24 else if not command -q fzfbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 25–29why, one step back25 echo "fzf was not found in path." >&226 return 127 end2829 function __fzf_defaultsfish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 30–31why, one step back30 # $argv[1]: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS31 # $argv[2..]: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTSbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 32–35why, one step back32 test -n "$FZF_TMUX_HEIGHT"; or set -l FZF_TMUX_HEIGHT 40%33 string join ' ' -- \34 "--height $FZF_TMUX_HEIGHT --min-height=20+ --bind=ctrl-z:ignore" $argv[1] \35 (test -r "$FZF_DEFAULT_OPTS_FILE"; and string join -- ' ' <$FZF_DEFAULT_OPTS_FILE) \fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
line 36why, one step back36 $FZF_DEFAULT_OPTS $argv[2..]bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 37–54why, one step back37 end3839 function __fzfcmd40 test -n "$FZF_TMUX_HEIGHT"; or set -l FZF_TMUX_HEIGHT 40%41 if test -n "$FZF_TMUX_OPTS"42 echo "fzf-tmux $FZF_TMUX_OPTS -- "43 else if test "$FZF_TMUX" = "1"44 echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "45 else46 echo "fzf"47 end48 end4950 function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'51 set -l fzf_query ''52 set -l prefix ''53 set -l dir '.'54fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
lines 55–56why, one step back55 set -l -- match_regex '(?<fzf_query>[\\s\\S]*?(?=\\n?$)$)'56 set -l -- prefix_regex '^-[^\\s=]+=|^-(?!-)\\S'bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 57why, one step back57fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
lines 58–60why, one step back58 # Don't use option prefix if " -- " is preceded.59 string match -qv -- '* -- *' (string sub -l (commandline -Cp) -- (commandline -p))60 and set -- match_regex "(?<prefix>$prefix_regex)?$match_regex"bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 61why, one step back61fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 62why, one step back62 # Set $prefix and expanded $fzf_query with preserved trailing newlines.fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
line 63why, one step back63 if string match -qr -- '^\\d\\d+|^[4-9]' $versionfish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 64why, one step back64 # fish v4.0.0 and newerbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 65–66why, one step back65 string match -q -r -- $match_regex (commandline --current-token --tokens-expanded | string collect -N)66 elsefish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
lines 67–68why, one step back67 string match -q -r -- $match_regex (commandline --current-token --tokenize | string collect -N)68 eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a '^\\\\(?=~)|\\\\(?=\\$\\w)' '')bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 69–71why, one step back69 end7071 if test -n "$fzf_query"fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 72why, one step back72 # Normalize path in $fzf_query, set $dir to the longest existing directory.fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
line 73why, one step back73 if string match -qr -- '^\\d\\d+|^4|^3\\.[5-9]' $versionfish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 74why, one step back74 # fish v3.5.0 and newerbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 75–80why, one step back75 set -- fzf_query (path normalize -- $fzf_query)76 set -- dir $fzf_query77 while not path is -d $dir78 set -- dir (path dirname $dir)79 end80 elsefish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
lines 81–82why, one step back81 string match -q -r -- '(?<fzf_query>^[\\s\\S]*?(?=\\n?$)$)' \82 (string replace -r -a -- '(?<=/)/|(?<!^)/+(?!\\n)$' '' $fzf_query | string collect -N)bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 83–88why, one step back83 set -- dir $fzf_query84 while not test -d "$dir"85 set -- dir (dirname -z -- "$dir" | string split0)86 end87 end88fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
line 89why, one step back89 if not string match -q -- '.' $dir; or string match -qr -- '^\\.(/|$)' $fzf_queryfish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 90why, one step back90 # Strip $dir from $fzf_query - preserve trailing newlines.fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
line 91why, one step back91 if string match -qr -- '^\\d\\d+|^[4-9]' $versionfish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 92why, one step back92 # fish v4.0.0 and newerfish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
line 93why, one step back93 string match -q -r -- '^'(string escape --style=regex -- $dir)'/?(?<fzf_query>[\\s\\S]*)' $fzf_querybash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 94why, one step back94 elsefish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
lines 95–96why, one step back95 string match -q -r -- '^/?(?<fzf_query>[\\s\\S]*?(?=\\n?$)$)' \96 (string replace -- "$dir" '' $fzf_query | string collect -N)bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 97–106why, one step back97 end98 end99 end100101 string escape -n -- "$dir" "$fzf_query" "$prefix"102 end103104 # Store current token in $dir as root for the 'find' command105 function fzf-file-widget -d "List files and folders"106 set -l commandline (__fzf_parse_commandline)fish: Improve custom CTRL-T command execution (#4909)bitraidbefore adoptionad151d8
line 107why, one step back107 set -l dir $commandline[1]bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 108–116why, one step back108 set -l fzf_query $commandline[2]109 set -l prefix $commandline[3]110111 set -lx FZF_DEFAULT_OPTS (__fzf_defaults \112 "--reverse --walker=file,dir,follow,hidden --scheme=path" \113 "--multi $FZF_CTRL_T_OPTS --print0")114115 set -lx FZF_DEFAULT_OPTS_FILE116fish: Improve custom CTRL-T command execution (#4909)bitraidbefore adoptionad151d8
lines 117–125why, one step back117 set -lx FZF_DEFAULT_COMMAND118119 if test -n "$FZF_CTRL_T_COMMAND"120 set -f result (eval $FZF_CTRL_T_COMMAND \| (__fzfcmd) --query=$fzf_query | string split0)121 else122 set -f result (eval (__fzfcmd) --walker-root=$dir --query=$fzf_query | string split0)123 end124125 test -n "$result"fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 126why, one step back126 and commandline -rt -- (string join -- ' ' $prefix(string escape -n -- $result))' 'bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 127–136why, one step back127128 commandline -f repaint129 end130131 function fzf-history-widget -d "Show command history"132 set -l -- command_line (commandline)133 set -l -- current_line (commandline -L)134 set -l -- total_lines (count $command_line)135 set -l -- fzf_query (string escape -- $command_line[$current_line])136fish: Don't use exported variable for history command (#4863)bitraidbefore adoptionb163463
lines 137–143why, one step back137 set -lx -- FZF_DEFAULT_COMMAND "builtin history -z --show-time=(set_color $fish_color_comment 2>/dev/null; or set_color normal)\"%F %a %T%t%s%t\"(set_color normal)"138139 # Enable syntax highlighting colors on fish v4.3.3 and newer140 if string match -qr -- '^\\d\\d+|^4\\.[4-9]|^4\\.3\\.[3-9]' $version141 set -a -- FZF_DEFAULT_COMMAND "--color=always"142 end143bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 144why, one step back144 set -lx -- FZF_DEFAULT_OPTS (__fzf_defaults '' \fish: Fixes and improvements to CTRL-R (#4703)bitraidbefore adoption9f8294d
lines 145–148why, one step back145 '--with-nth=2.. --nth=2..,.. --scheme=history --multi --no-multi-line' \146 '--no-wrap --wrap-sign="\t\t\t↳ " --preview-wrap-sign="↳ " --freeze-left=1' \147 '--bind="alt-enter:become(set -g fzf_temp {+sf3..}; string join0 -- (string split0 -- <$fzf_temp | fish_indent -i); unlink $fzf_temp &>/dev/null)"' \148 '--bind="alt-t:change-with-nth(1,3..|3..|2..)"' \fish: Don't use exported variable for history command (#4863)bitraidbefore adoptionb163463
line 149why, one step back149 "--bind='shift-delete:execute-silent(eval builtin history delete -Ce -- (string escape -n -- (string split0 -- <{+sf3..})))+reload($FZF_DEFAULT_COMMAND)'" \bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 150why, one step back150 "--bind=ctrl-r:toggle-sort,alt-r:toggle-raw --highlight-line $FZF_CTRL_R_OPTS" \fish: Don't use exported variable for history command (#4863)bitraidbefore adoptionb163463
line 151why, one step back151 '--accept-nth=3.. --delimiter="\t" --tabstop=4 --ansi --read0 --print0 --with-shell='(status fish-path)\\ -c)bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 152–154why, one step back152153 # Add dynamic preview options if preview command isn't already set by user154 if string match -qvr -- '--preview[= ]' "$FZF_DEFAULT_OPTS"fish: Fixes and improvements to CTRL-R (#4703)bitraidbefore adoption9f8294d
line 155why, one step back155 # Prepend the options to allow user overridesbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 156why, one step back156 set -p -- FZF_DEFAULT_OPTS \fish: Key bindings now requires fish v3.4.0+bitraidbefore adoption59b8267
lines 157–158why, one step back157 '--bind="focus,multi,resize:bg-transform:if test \\"$FZF_COLUMNS\\" -gt 100 -a \\\\( \\"$FZF_SELECT_COUNT\\" -gt 0 -o \\\\( -z \\"$FZF_WRAP\\" -a (string join0 -- <{f3..} | string length) -gt (math $FZF_COLUMNS - (switch $FZF_WITH_NTH; case 2..; echo 13; case 1,3..; echo 25; case 3..; echo 1; end)) \\\\) -o (string split0 -- <{sf3..} | fish_indent | count) -gt 1 \\\\); echo show-preview; else; echo hide-preview; end"' \158 '--preview="test \\"$FZF_SELECT_COUNT\\" -gt 0; and string split0 -- <{+sf3..} | fish_indent (string match -q -- 3.\\\\* $version; or echo -- --only-indent) --ansi; and echo -n \\\\n; string collect -- \\\\#\\\\ {1} (string split0 -- <{sf3..}) | fish_indent --ansi"' \bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 159–223why, one step back159 '--preview-window="right,50%,wrap-word,follow,info,hidden"'160 end161162 set -lx FZF_DEFAULT_OPTS_FILE163164 # Merge history from other sessions before searching165 test -z "$fish_private_mode"; and builtin history merge166167 if set -l result (eval $FZF_DEFAULT_COMMAND \| (__fzfcmd) --query=$fzf_query | string split0)168 if test "$total_lines" -eq 1169 commandline -- $result170 else171 set -l a (math $current_line - 1)172 set -l b (math $current_line + 1)173 commandline -- $command_line[1..$a] $result174 commandline -a -- '' $command_line[$b..-1]175 end176 end177178 commandline -f repaint179 end180181 function fzf-cd-widget -d "Change directory"182 set -l commandline (__fzf_parse_commandline)183 set -lx dir $commandline[1]184 set -l fzf_query $commandline[2]185 set -l prefix $commandline[3]186187 set -lx FZF_DEFAULT_OPTS (__fzf_defaults \188 "--reverse --walker=dir,follow,hidden --scheme=path" \189 "$FZF_ALT_C_OPTS --no-multi --print0")190191 set -lx FZF_DEFAULT_OPTS_FILE192 set -lx FZF_DEFAULT_COMMAND "$FZF_ALT_C_COMMAND"193194 if set -l result (eval (__fzfcmd) --query=$fzf_query --walker-root=$dir | string split0)195 cd -- $result196 commandline -rt -- $prefix197 end198199 commandline -f repaint200 end201202 if not set -q FZF_CTRL_R_COMMAND; or test -n "$FZF_CTRL_R_COMMAND"203 if test -n "$FZF_CTRL_R_COMMAND"204 echo "warning: FZF_CTRL_R_COMMAND is set to a custom command, but custom commands are not yet supported for CTRL-R" >&2205 end206 bind \cr fzf-history-widget207 bind -M insert \cr fzf-history-widget208 end209210 if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"211 bind \ct fzf-file-widget212 bind -M insert \ct fzf-file-widget213 end214215 if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"216 bind \ec fzf-cd-widget217 bind -M insert \ec fzf-cd-widget218 end219220end221222# Run setup223fzf_key_bindings