Skip to content
Myr

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 file

Take 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 back
1# ____ ____
2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/5# /_/ /___/_/ completion.fish6#

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 7–8why, one step back
7# - $FZF_COMPLETION_OPTS
8# - $FZF_EXPANSION_OPTS

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 9why, one step back
9

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 10–19why, one step back
10# The oldest supported fish version is 3.4.0. For this message being able to be
11# 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 119end

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 20why, one step back
20

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 21–25why, one step back
21function 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 return

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 26–27why, one step back
26 end
27

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 28–30why, one step back
28 # Remove any trailing unescaped backslash from token and update command line
29 set -l -- token (string replace -r -- '(?<!\\\\)(?:\\\\\\\\)*\\K\\\\$' '' (commandline -t | string collect) | string collect)30 commandline -rt -- $token

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 31why, one step back
31

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 32–33why, one step back
32 # Remove any line breaks from token
33 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 back
34

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 35–36why, one step back
35 # regex: Match token with unescaped/unquoted glob character
36 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 back
37

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 38–39why, one step back
38 # regex: Match any unbalanced quote character
39 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 back
40

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 41–42why, one step back
41 # 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 back
43

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 44–46why, one step back
44 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 back
47

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 48–53why, one step back
48 # Set command line tokens without any leading variable definitions or launcher
49 # 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 back
54

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 55–57why, one step back
55 # Set fzf options
56 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 back
58

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 59–65why, one step back
59 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)\\ -c

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 66why, one step back
66

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

line 67why, one step back
67 set -lx FZF_DEFAULT_OPTS_FILE

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 68why, one step back
68

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 69–71why, one step back
69 set -l -- fzf_cmd fzf
70 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 back
72

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

line 73why, one step back
73 set -l result

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 74why, one step back
74

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 75–79why, one step back
75 # Get the completion list from stdin when it's not a tty
76 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]_post

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 80why, one step back
80

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 81–86why, one step back
81 if functions -q $custom_post_func
82 $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; end

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 87–88why, one step back
87 end
88

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 89–95why, one step back
89 # Wildcard expansion
90 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 back
96

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

line 97why, one step back
97 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 back
98

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 99–106why, one step back
99 # Command completion
100 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 return

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 107–108why, one step back
107 end
108

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 109–113why, one step back
109 # Workaround for complete not having newlines in results
110 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 back
114 end
115

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 116–126why, one step back
116 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 back
127 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 back
129 and set -- tabstop $len
130 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 back
134 end
135 end136

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 137–143why, one step back
137 # Update command line
138 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 back
144

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

line 145why, one step back
145 commandline -rt -- (string join -- ' ' $result)$tail

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 146–147why, one step back
146 end
147

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 148–155why, one step back
148 commandline -f repaint
149end150151function _fzf_complete152 set -l fzf_args153 for i in $argv154 string match -q -- '--' $i; and break155 set -a -- fzf_args $i

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 156why, one step back
156 end

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

line 157why, one step back
157 fzf_complete $fzf_args

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 158–159why, one step back
158end
159

fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2

lines 160–167why, one step back
160# Bind to shift-tab
161if 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