completion.fish
This file
Path
shell/completion.fish
167 lines · 6.1 KiB
Last changed by
fish: Optimize description alignment of completions (#4912)bitraidbefore adoptiona1e983b
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–6why, one step back1# ____ ____2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/5# /_/ /___/_/ completion.fish6#fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 7–8why, one step back7# - $FZF_COMPLETION_OPTS8# - $FZF_EXPANSION_OPTSbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 9why, one step back9fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 10–19why, one step back10# The oldest supported fish version is 3.4.0. For this message being able to be11# displayed on older versions, the command substitution syntax $() should not12# be used anywhere in the script, otherwise the source command will fail.13if string match -qr -- '^[12]\\.|^3\\.[0-3]' $version14 echo "fzf completion script requires fish version 3.4.0 or newer." >&215 return 116else if not command -q fzf17 echo "fzf was not found in path." >&218 return 119endbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 20why, one step back20fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 21–25why, one step back21function fzf_complete -w fzf -d 'fzf command completion and wildcard expansion search'22 # Restore the default shift-tab behavior on tab completions23 if commandline --paging-mode24 commandline -f complete-and-search25 returnbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 26–27why, one step back26 end27fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 28–30why, one step back28 # Remove any trailing unescaped backslash from token and update command line29 set -l -- token (string replace -r -- '(?<!\\\\)(?:\\\\\\\\)*\\K\\\\$' '' (commandline -t | string collect) | string collect)30 commandline -rt -- $tokenbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 31why, one step back31fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 32–33why, one step back32 # Remove any line breaks from token33 set -- token (string replace -ra -- '\\\\\\n' '' $token | string collect)bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 34why, one step back34fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 35–36why, one step back35 # regex: Match token with unescaped/unquoted glob character36 set -l -- r_glob '^(?:[^\'"\\\\*]|\\\\[\\S\\s]|\'(?:\\\\[\\S\\s]|[^\'\\\\])*\'|"(?:\\\\[\\S\\s]|[^"\\\\])*")*\\*[\\S\\s]*$'bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 37why, one step back37fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 38–39why, one step back38 # regex: Match any unbalanced quote character39 set -l -- r_quote '^(?>(?:\\\\[\\s\\S]|"(?:[^"\\\\]|\\\\[\\s\\S])*"|\'(?:[^\'\\\\]|\\\\[\\s\\S])*\'|[^\'"\\\\]+)*)\\K[\'"]'bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 40why, one step back40fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 41–42why, one step back41 # The expansion pattern is the token with any open quote closed, or is empty.42 set -l -- glob_pattern (string match -r -- $r_glob $token | string collect)(string match -r -- $r_quote $token | string collect -a)bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 43why, one step back43fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 44–46why, one step back44 set -l -- cl_tokenize_opt '--tokens-expanded'45 string match -q -- '3.*' $version46 and set -- cl_tokenize_opt '--tokenize'bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 47why, one step back47fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 48–53why, one step back48 # Set command line tokens without any leading variable definitions or launcher49 # commands (including their options, but not any option arguments).50 set -l -- r_cmd '^(?:(?:builtin|command|doas|env|sudo|\\w+=\\S*|-\\S+)\\s+)*\\K[\\s\\S]+'51 set -l -- cmd (commandline $cl_tokenize_opt --input=(commandline -pc | string match -r $r_cmd))52 test -z "$token"53 and set -a -- cmd ''bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 54why, one step back54fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 55–57why, one step back55 # Set fzf options56 test -z "$FZF_TMUX_HEIGHT"57 and set -l -- FZF_TMUX_HEIGHT 40%bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 58why, one step back58fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 59–65why, one step back59 set -lax -- FZF_DEFAULT_OPTS \60 "--height=$FZF_TMUX_HEIGHT --min-height=20+ --bind=ctrl-z:ignore" \61 (test -r "$FZF_DEFAULT_OPTS_FILE"; and string join -- ' ' <$FZF_DEFAULT_OPTS_FILE) \62 $FZF_DEFAULT_OPTS '--bind=alt-r:toggle-raw --multi --wrap=word --reverse' \63 (if test -n "$glob_pattern"; string collect -- $FZF_EXPANSION_OPTS; else;64 string collect -- $FZF_COMPLETION_OPTS; end; string escape -n -- $argv) \65 --with-shell=(status fish-path)\\ -cbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 66why, one step back66fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 67why, one step back67 set -lx FZF_DEFAULT_OPTS_FILEbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 68why, one step back68fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 69–71why, one step back69 set -l -- fzf_cmd fzf70 test "$FZF_TMUX" = 171 and set -- fzf_cmd fzf-tmux $FZF_TMUX_OPTS -d$FZF_TMUX_HEIGHT --bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 72why, one step back72fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 73why, one step back73 set -l resultbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 74why, one step back74fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 75–79why, one step back75 # Get the completion list from stdin when it's not a tty76 if not isatty stdin77 set -l -- custom_post_func _fzf_post_complete_$cmd[1]78 functions -q $custom_post_func79 or set -- custom_post_func _fzf_complete_$cmd[1]_postbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 80why, one step back80fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 81–86why, one step back81 if functions -q $custom_post_func82 $fzf_cmd | $custom_post_func $cmd | while read -l r; set -a -- result $r; end83 else if string match -q -- '*--print0*' "$FZF_DEFAULT_OPTS"84 $fzf_cmd | while read -lz r; set -a -- result $r; end85 else86 $fzf_cmd | while read -l r; set -a -- result $r; endbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 87–88why, one step back87 end88fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 89–95why, one step back89 # Wildcard expansion90 else if test -n "$glob_pattern"91 # Set the command to be run by fzf, so there is a visual indicator and an92 # easy way to abort on long recursive searches.93 set -lx -- FZF_DEFAULT_COMMAND "for i in $glob_pattern;" \94 'test -d "$i"; and string match -qv -- "*/" $i; and set -- i $i/;' \95 'string join0 -- $i; end'bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 96why, one step back96fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 97why, one step back97 set -- result (string escape -n -- ($fzf_cmd --read0 --print0 --scheme=path --no-multi-line | string split0))bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 98why, one step back98fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 99–106why, one step back99 # Command completion100 else101 # Call custom function if defined102 set -l -- custom_func _fzf_complete_$cmd[1]103 if functions -q $custom_func; and not set -q __fzf_no_custom_complete104 set -lx __fzf_no_custom_complete105 $custom_func $cmd106 returnbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 107–108why, one step back107 end108fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 109–113why, one step back109 # Workaround for complete not having newlines in results110 if string match -qr -- '\\n' $token111 set -- token (string replace -ra -- '(?<!\\\\)(?:\\\\\\\\)*\\K\\\\\$' '\\\\\\\\\$' $token | string collect)112 set -- token (string unescape -- $token | string collect)113 set -- token (string replace -ra -- '\\n' '\\\\n' $token | string collect)bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 114–115why, one step back114 end115fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 116–126why, one step back116 set -- list (complete -C --escape -- (string join -- ' ' (commandline -pc $cl_tokenize_opt) $token | string collect))117 if test -n "$list"118 # Get the initial tabstop value119 if set -l -- tabstop (string match -rga -- '--tabstop[= ](?:0*)([1-9]\\d+|[4-9])' "$FZF_DEFAULT_OPTS")[-1]120 set -- tabstop (math $tabstop - 4)121 else122 set -- tabstop 4123 end124125 # Determine the tabstop length for description alignment126 set -l -- max_columns (math $COLUMNS - 40)fish: Optimize description alignment of completions (#4912)bitraidbefore adoptiona1e983b
lines 127–128why, one step back127 for len in (string match -r -- '^[^\\t]*(?=\\t)' $list[1..500] | string length -V)128 test "$len" -gt "$tabstop" -a "$len" -lt "$max_columns"fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 129–133why, one step back129 and set -- tabstop $len130 end131 set -- tabstop (math $tabstop + 4)132133 set -- result (string collect -- $list | $fzf_cmd --delimiter="\t" --tabstop=$tabstop --wrap-sign=\t"↳ " --accept-nth=1)bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 134–136why, one step back134 end135 end136fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 137–143why, one step back137 # Update command line138 if test -n "$result"139 # No extra space after single selection that ends with path separator140 set -l -- tail ' '141 test (count $result) -eq 1142 and string match -q -- '*/' "$result"143 and set -- tail ''bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 144why, one step back144fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 145why, one step back145 commandline -rt -- (string join -- ' ' $result)$tailbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 146–147why, one step back146 end147fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 148–155why, one step back148 commandline -f repaint149end150151function _fzf_complete152 set -l fzf_args153 for i in $argv154 string match -q -- '--' $i; and break155 set -a -- fzf_args $ibash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 156why, one step back156 endfish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 157why, one step back157 fzf_complete $fzf_argsbash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 158–159why, one step back158end159fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 160–167why, one step back160# Bind to shift-tab161if string match -qr -- '^\\d\\d+|^[4-9]' $version162 bind shift-tab fzf_complete163 bind -M insert shift-tab fzf_complete164else165 bind -k btab fzf_complete166 bind -M insert -k btab fzf_complete167end