| 1 |
# This script was generated by crazy-complete. |
| 2 |
# crazy-complete: A tool that creates robust and reliable autocompletion scripts for Bash, Fish and Zsh. |
| 3 |
# For more information, visit: https://github.com/crazy-complete/crazy-complete |
| 4 |
|
| 5 |
function _example__list |
| 6 |
set -l duplicates false |
| 7 |
|
| 8 |
if test $argv[1] = '-d' |
| 9 |
set duplicates true |
| 10 |
set -e argv[1] |
| 11 |
end |
| 12 |
|
| 13 |
set -l separator $argv[1] |
| 14 |
set -l func $argv[2] |
| 15 |
set -l comp (_example__get_completing_arg) |
| 16 |
|
| 17 |
if test -z "$comp" |
| 18 |
eval $func |
| 19 |
return |
| 20 |
end |
| 21 |
|
| 22 |
set -l i |
| 23 |
set -l value |
| 24 |
set -l values |
| 25 |
set -l descriptions |
| 26 |
|
| 27 |
set -g __fish_stripprefix "^.*"(string escape --style=regex -- $separator) |
| 28 |
|
| 29 |
for value in (eval $func) |
| 30 |
set -l split (string split -- \t $value) |
| 31 |
set -a values $split[1] |
| 32 |
set -a descriptions "$split[2]" |
| 33 |
end |
| 34 |
|
| 35 |
set -e __fish_stripprefix |
| 36 |
|
| 37 |
set -l having_values (string split -- $separator $comp) |
| 38 |
set -l remaining_values_idxs |
| 39 |
|
| 40 |
if $duplicates |
| 41 |
set remaining_values_idxs (command seq 1 (count $values)) |
| 42 |
else |
| 43 |
set i 1 |
| 44 |
for value in $values |
| 45 |
if not contains -- $value $having_values |
| 46 |
set -a remaining_values_idxs $i |
| 47 |
end |
| 48 |
|
| 49 |
set i (math $i + 1) |
| 50 |
end |
| 51 |
end |
| 52 |
|
| 53 |
switch $comp |
| 54 |
case "*$separator" |
| 55 |
for i in $remaining_values_idxs |
| 56 |
printf '%s%s\t%s\n' $comp $values[$i] "$descriptions[$i]" |
| 57 |
end |
| 58 |
case "*$separator*" |
| 59 |
set comp (string split -r -m 1 -- $separator $comp)[1] |
| 60 |
|
| 61 |
for i in $remaining_values_idxs |
| 62 |
printf '%s%s%s\t%s\n' "$comp" $separator $values[$i] "$descriptions[$i]" |
| 63 |
end |
| 64 |
case '*' |
| 65 |
for i in $remaining_values_idxs |
| 66 |
printf '%s\t%s\n' $values[$i] "$descriptions[$i]" |
| 67 |
end |
| 68 |
end |
| 69 |
end |
| 70 |
|
| 71 |
function _example__get_completing_arg |
| 72 |
set -l arg (commandline -ct | string unescape) |
| 73 |
|
| 74 |
switch $arg |
| 75 |
case '--*=' '--*=*' |
| 76 |
set arg (string replace -r -- '^-[^=]*=' '' $arg) |
| 77 |
case '-*' |
| 78 |
set -l prog (commandline -po)[1] |
| 79 |
set -l progdef (complete -c $prog) |
| 80 |
|
| 81 |
set -l full_opt (string match -r -- '^-[a-zA-Z0-9]+=' $arg) |
| 82 |
set -l opt (string sub -s 2 -e -1 -- $full_opt) |
| 83 |
set -l optdefs (string match -re -- " -(o|-old-option) $opt( |\$)" $progdef) |
| 84 |
set -l optdefs (string match -re -- " -(x|r|a|-(exclusive|require-parameter|arguments))( |\$)" $optdefs) |
| 85 |
|
| 86 |
if test (count $optdefs) -gt 0 |
| 87 |
set arg (string replace -m 1 -- $full_opt '' $arg) |
| 88 |
else |
| 89 |
set -l i 2 |
| 90 |
|
| 91 |
while test $i -lt (string length -- $arg) |
| 92 |
set -l opt (string sub -s $i -l 1 -- $arg) |
| 93 |
set -l optdefs (string match -re -- " -(s|-short-option) $opt( |\$)" $progdef) |
| 94 |
set -l optdefs (string match -re -- " -(x|r|a|-(exclusive|require-parameter|arguments))( |\$)" $optdefs) |
| 95 |
|
| 96 |
if test (count $optdefs) -gt 0 |
| 97 |
set arg (string sub -s (math $i + 1) -- "$arg") |
| 98 |
break |
| 99 |
end |
| 100 |
|
| 101 |
set i (math $i + 1) |
| 102 |
end |
| 103 |
end |
| 104 |
end |
| 105 |
|
| 106 |
if test -n "$__fish_stripprefix" |
| 107 |
string replace -r -- $__fish_stripprefix '' "$arg" |
| 108 |
else |
| 109 |
printf '%s\n' "$arg" |
| 110 |
end |
| 111 |
end |
| 112 |
|
| 113 |
function _example__key_value_list |
| 114 |
set -l sep1 $argv[1] |
| 115 |
set -l sep2 $argv[2] |
| 116 |
set -l value |
| 117 |
set -l keys |
| 118 |
set -l descriptions |
| 119 |
set -l functions |
| 120 |
set -l i |
| 121 |
|
| 122 |
for i in (command seq 3 3 (count $argv)) |
| 123 |
set -a keys $argv[$i] |
| 124 |
set -a descriptions $argv[(math $i + 1)] |
| 125 |
set -a functions $argv[(math $i + 2)] |
| 126 |
end |
| 127 |
|
| 128 |
set -l comp (_example__get_completing_arg) |
| 129 |
|
| 130 |
if test -z "$comp" || test (string sub -s -1 -l 1 -- $comp) = $sep1 |
| 131 |
for i in (command seq 1 (count $keys)) |
| 132 |
if test "$functions[$i]" = false |
| 133 |
printf '%s%s\t%s\n' "$comp" $keys[$i] "$descriptions[$i]" |
| 134 |
else |
| 135 |
printf '%s%s%s\t%s\n' "$comp" $keys[$i] $sep2 "$descriptions[$i]" |
| 136 |
end |
| 137 |
end |
| 138 |
return |
| 139 |
end |
| 140 |
|
| 141 |
function _example__call_func_for_key -S |
| 142 |
set -l i |
| 143 |
for i in (command seq 1 (count $keys)) |
| 144 |
if test $keys[$i] = $argv[1] |
| 145 |
set -g __fish_stripprefix "^.*"(string escape --style=regex -- $sep2) |
| 146 |
$functions[$i] |
| 147 |
set -e __fish_stripprefix |
| 148 |
return |
| 149 |
end |
| 150 |
end |
| 151 |
end |
| 152 |
|
| 153 |
set -l pair (string split -- $sep1 $comp)[-1] |
| 154 |
set -l split (string split -- $sep2 $pair) |
| 155 |
|
| 156 |
switch $pair |
| 157 |
case "*$sep2*" |
| 158 |
set -l value_len (string length -- $split[2]) |
| 159 |
|
| 160 |
if test $value_len -gt 0 |
| 161 |
set comp (string sub -e -$value_len -- $comp) |
| 162 |
end |
| 163 |
|
| 164 |
for value in (_example__call_func_for_key $split[1]) |
| 165 |
printf '%s%s\n' $comp $value |
| 166 |
end |
| 167 |
case '*' |
| 168 |
set -l key_len (string length -- $split[1]) |
| 169 |
set comp (string sub -e -$key_len -- $comp) |
| 170 |
|
| 171 |
for i in (command seq 1 (count $keys)) |
| 172 |
if test "$functions[$i]" = false |
| 173 |
printf '%s%s\t%s\n' "$comp" $keys[$i] "$descriptions[$i]" |
| 174 |
else |
| 175 |
printf '%s%s%s\t%s\n' "$comp" $keys[$i] $sep2 "$descriptions[$i]" |
| 176 |
end |
| 177 |
end |
| 178 |
end |
| 179 |
end |
| 180 |
|
| 181 |
function _example__query |
| 182 |
|
| 183 |
set -l positionals |
| 184 |
set -l positionals_positions |
| 185 |
set -l having_options |
| 186 |
set -l option_values |
| 187 |
|
| 188 |
set -l options $argv[1] |
| 189 |
set -e argv[1] |
| 190 |
|
| 191 |
set -l cmd $argv[1] |
| 192 |
set -e argv[1] |
| 193 |
|
| 194 |
set -l my_cache_key "$(commandline -b) $options" |
| 195 |
|
| 196 |
if test "$__QUERY_CACHE_KEY" = "$my_cache_key" |
| 197 |
set positionals $__QUERY_CACHE_POSITIONALS |
| 198 |
set positionals_positions $__QUERY_CACHE_POSITIONALS_POSITIONS |
| 199 |
set having_options $__QUERY_CACHE_HAVING_OPTIONS |
| 200 |
set option_values $__QUERY_CACHE_OPTION_VALUES |
| 201 |
else |
| 202 |
|
| 203 |
set -l short_opts_with_arg |
| 204 |
set -l short_opts_without_arg |
| 205 |
set -l short_opts_with_optional_arg |
| 206 |
set -l long_opts_with_arg |
| 207 |
set -l long_opts_without_arg |
| 208 |
set -l long_opts_with_optional_arg |
| 209 |
|
| 210 |
set -l option |
| 211 |
|
| 212 |
if test -n "$options" |
| 213 |
for option in (string split -- ',' $options) |
| 214 |
if false |
| 215 |
true |
| 216 |
else if string match -qr -- '^--.+=$' $option |
| 217 |
set -a long_opts_with_arg (string replace -- '=' '' $option) |
| 218 |
else if string match -qr -- '^--.+=\?$' $option |
| 219 |
set -a long_opts_with_optional_arg (string replace -- '=?' '' $option) |
| 220 |
else if string match -qr -- '^--.+$' $option |
| 221 |
set -a long_opts_without_arg $option |
| 222 |
else if string match -qr -- '^-.=$' $option |
| 223 |
set -a short_opts_with_arg (string replace -- '=' '' $option) |
| 224 |
else if string match -qr -- '^-.=\?$' $option |
| 225 |
set -a short_opts_with_optional_arg (string replace -- '=?' '' $option) |
| 226 |
else if string match -qr -- '^-.$' $option |
| 227 |
set -a short_opts_without_arg $option |
| 228 |
end |
| 229 |
end |
| 230 |
end |
| 231 |
|
| 232 |
set -l cmdline (commandline -poc) |
| 233 |
set -l cmdline_count (count $cmdline) |
| 234 |
|
| 235 |
set -l argi 2 # cmdline[1] is command name |
| 236 |
while test $argi -le $cmdline_count |
| 237 |
set -l arg "$cmdline[$argi]" |
| 238 |
set -l have_trailing_arg (test $argi -lt $cmdline_count && echo true || echo false) |
| 239 |
|
| 240 |
switch $arg |
| 241 |
case '-' |
| 242 |
set -a positionals - |
| 243 |
set -s positionals_positions $argi |
| 244 |
case '--' |
| 245 |
set -a positionals $cmdline[$(math $argi + 1)..] |
| 246 |
set -a positionals_positions (command seq (math $argi + 1) $cmdline_count) |
| 247 |
break |
| 248 |
case '--*=*' |
| 249 |
set -l split (string split -m 1 -- '=' $arg) |
| 250 |
set -a having_options $split[1] |
| 251 |
set -a option_values "$split[2]" |
| 252 |
case '--*' |
| 253 |
if contains -- $arg $long_opts_with_arg |
| 254 |
if $have_trailing_arg |
| 255 |
set -a having_options $arg |
| 256 |
set -a option_values $cmdline[(math $argi + 1)] |
| 257 |
set argi (math $argi + 1) |
| 258 |
end |
| 259 |
else |
| 260 |
set -a having_options $arg |
| 261 |
set -a option_values '' |
| 262 |
end |
| 263 |
case '-*' |
| 264 |
set -l end_of_parsing false |
| 265 |
|
| 266 |
set -l arg_length (string length -- $arg) |
| 267 |
set -l i 2 |
| 268 |
while not $end_of_parsing; and test $i -le $arg_length |
| 269 |
set -l option "-$(string sub -s $i -l 1 -- $arg)" |
| 270 |
set -l trailing_chars "$(string sub -s (math $i + 1) -- $arg)" |
| 271 |
|
| 272 |
if contains -- $option $short_opts_without_arg |
| 273 |
set -a having_options $option |
| 274 |
set -a option_values '' |
| 275 |
else if contains -- $option $short_opts_with_arg |
| 276 |
set end_of_parsing true |
| 277 |
|
| 278 |
if test -n "$trailing_chars" |
| 279 |
set -a having_options $option |
| 280 |
set -a option_values $trailing_chars |
| 281 |
else if $have_trailing_arg |
| 282 |
set -a having_options $option |
| 283 |
set -a option_values $cmdline[(math $argi + 1)] |
| 284 |
set argi (math $argi + 1) |
| 285 |
end |
| 286 |
else if contains -- $option $short_opts_with_optional_arg |
| 287 |
set end_of_parsing true |
| 288 |
set -a having_options $option |
| 289 |
set -a option_values "$trailing_chars" # may be empty |
| 290 |
end |
| 291 |
|
| 292 |
set i (math $i + 1) |
| 293 |
end |
| 294 |
case '*' |
| 295 |
set -a positionals $arg |
| 296 |
set -a positionals_positions $argi |
| 297 |
end |
| 298 |
|
| 299 |
set argi (math $argi + 1) |
| 300 |
end |
| 301 |
|
| 302 |
set -g __QUERY_CACHE_POSITIONALS $positionals |
| 303 |
set -g __QUERY_CACHE_POSITIONALS_POSITIONS $positionals_positions |
| 304 |
set -g __QUERY_CACHE_HAVING_OPTIONS $having_options |
| 305 |
set -g __QUERY_CACHE_OPTION_VALUES $option_values |
| 306 |
set -g __QUERY_CACHE_KEY $my_cache_key |
| 307 |
end |
| 308 |
|
| 309 |
switch $cmd |
| 310 |
case 'positional_contains' |
| 311 |
set -l positional_num $argv[1] |
| 312 |
set -e argv[1] |
| 313 |
contains -- $positionals[$positional_num] $argv && return 0 || return 1 |
| 314 |
case 'has_option' |
| 315 |
set -l with_incomplete false |
| 316 |
|
| 317 |
if test $argv[1] = 'WITH_INCOMPLETE' |
| 318 |
set with_incomplete true |
| 319 |
set -e argv[1] |
| 320 |
end |
| 321 |
|
| 322 |
for option in $having_options |
| 323 |
contains -- $option $argv && return 0 |
| 324 |
end |
| 325 |
|
| 326 |
if $with_incomplete |
| 327 |
set -l tokens (commandline -po) |
| 328 |
set -e tokens[1] |
| 329 |
for option in $argv |
| 330 |
if test 2 -eq (string length -- $option) |
| 331 |
set option (string sub -l 1 -s 2 -- $option) |
| 332 |
string match -q -r -- "^-[A-z0-9]*$option\$" $tokens[-2] && return 0 |
| 333 |
string match -q -r -- "^-[A-z0-9]*$option.*\$" $tokens[-1] && return 0 |
| 334 |
else |
| 335 |
string match -q -r -- "^$option\$" $tokens[-2] && return 0 |
| 336 |
string match -q -r -- "^$option(=.*)?\$" $tokens[-1] && return 0 |
| 337 |
contains -- $tokens[-1] $argv && return 0 |
| 338 |
end |
| 339 |
end |
| 340 |
end |
| 341 |
|
| 342 |
return 1 |
| 343 |
case 'num_of_positionals' |
| 344 |
switch (count $argv) |
| 345 |
case 0 |
| 346 |
count $positionals |
| 347 |
case 2 |
| 348 |
if contains -- $argv[1] -lt -le -eq -ne -gt -ge; |
| 349 |
test (count $positionals) $argv[1] $argv[2] && return 0 || return 1 |
| 350 |
end |
| 351 |
end |
| 352 |
case 'positional_pos' |
| 353 |
echo $positionals_positions[$argv[1]] |
| 354 |
end |
| 355 |
end |
| 356 |
|
| 357 |
function _example_start__--preserve-env |
| 358 |
set -n -x |
| 359 |
end |
| 360 |
|
| 361 |
function _example_start__-o |
| 362 |
command locale -a |
| 363 |
end |
| 364 |
|
| 365 |
function _example_start__-o0 |
| 366 |
_example__key_value_list , = \ |
| 367 |
lang 'set language' _example_start__-o \ |
| 368 |
user 'set user' __fish_complete_users \ |
| 369 |
group 'set group' __fish_complete_groups |
| 370 |
end |
| 371 |
|
| 372 |
function _example_start__--priority |
| 373 |
printf '%s\t%s\n' \ |
| 374 |
low 'Run with lowest priority, background tasks only' \ |
| 375 |
normal 'Standard scheduling priority for regular tasks' \ |
| 376 |
high 'Higher priority for time-sensitive operations' \ |
| 377 |
realtime 'Real-time scheduling, may affect system responsiveness' |
| 378 |
end |
| 379 |
|
| 380 |
function _example_start__argument |
| 381 |
set -l opts -v,--verbose,--deprecated-option,--preserve-env=,--priority=,--foreground,--background,--pid-file=,-o=,--options=,-h,--help |
| 382 |
set -l pos (_example__query "$opts" positional_pos 2) |
| 383 |
set -l cmdline (commandline -poc | string escape) (commandline -ct) |
| 384 |
complete -C -- "$cmdline[$pos..]" |
| 385 |
end |
| 386 |
|
| 387 |
set -l prog 'example' |
| 388 |
set -l query '_example__query' |
| 389 |
|
| 390 |
# Delete existing completions |
| 391 |
complete -c $prog -e |
| 392 |
|
| 393 |
# Generally disable file completion |
| 394 |
complete -c $prog -x |
| 395 |
|
| 396 |
# command example |
| 397 |
set -l opts "-h,--help" |
| 398 |
set -l C000 "not $query '$opts' has_option -h --help && not $query '$opts' num_of_positionals -ge 2" |
| 399 |
set -l C001 "$query '$opts' num_of_positionals -eq 0" |
| 400 |
complete -c $prog -n $C000 -s h -l help -f |
| 401 |
complete -c $prog -n $C001 -d Commands -f -a "start\\t'' launch\\t'' view-log\\t''" |
| 402 |
|
| 403 |
# command example start |
| 404 |
set -l opts "-v,--verbose,--deprecated-option,--preserve-env=,--priority=,--foreground,--background,--pid-file=,-o=,--options=,-h,--help" |
| 405 |
set -l C000 "$query '$opts' positional_contains 1 start launch && not $query '$opts' has_option -h --help && not $query '$opts' num_of_positionals -ge 2" |
| 406 |
set -l C001 "$query '$opts' positional_contains 1 start launch && not $query '$opts' has_option -h --help --deprecated-option && $query '$opts' has_option WITH_INCOMPLETE --deprecated-option && not $query '$opts' num_of_positionals -ge 2" |
| 407 |
set -l C002 "$query '$opts' positional_contains 1 start launch && not $query '$opts' has_option -h --help --preserve-env && not $query '$opts' num_of_positionals -ge 2" |
| 408 |
set -l C003 "$query '$opts' positional_contains 1 start launch && not $query '$opts' has_option -h --help --priority && not $query '$opts' num_of_positionals -ge 2" |
| 409 |
set -l C004 "$query '$opts' positional_contains 1 start launch && not $query '$opts' has_option -h --help --background --foreground && not $query '$opts' num_of_positionals -ge 2" |
| 410 |
set -l C005 "$query '$opts' positional_contains 1 start launch && not $query '$opts' has_option -h --help --foreground --background && not $query '$opts' num_of_positionals -ge 2" |
| 411 |
set -l C006 "$query '$opts' positional_contains 1 start launch && $query '$opts' has_option --background && not $query '$opts' has_option -h --help --pid-file && not $query '$opts' num_of_positionals -ge 2" |
| 412 |
set -l C007 "$query '$opts' positional_contains 1 start launch && not $query '$opts' has_option -h --help -o --options && not $query '$opts' num_of_positionals -ge 2" |
| 413 |
set -l C008 "$query '$opts' num_of_positionals -eq 1 && $query '$opts' positional_contains 1 start launch" |
| 414 |
set -l C009 "$query '$opts' num_of_positionals -ge 2 && $query '$opts' positional_contains 1 start launch" |
| 415 |
complete -c $prog -n $C000 -s v -l verbose -f |
| 416 |
complete -c $prog -n $C001 -l deprecated-option -f |
| 417 |
complete -c $prog -n $C002 -l preserve-env -x -a '(_example__list , _example_start__--preserve-env)' |
| 418 |
complete -c $prog -n $C003 -l priority -kx -a '(_example_start__--priority)' |
| 419 |
complete -c $prog -n $C004 -l foreground -f |
| 420 |
complete -c $prog -n $C005 -l background -f |
| 421 |
complete -c $prog -n $C006 -l pid-file -Fr |
| 422 |
complete -c $prog -n $C007 -s o -l options -x -a '(_example_start__-o0)' |
| 423 |
complete -c $prog -n $C008 -x -a '(__fish_complete_command)' |
| 424 |
complete -c $prog -n $C009 -x -a '(_example_start__argument)' |
| 425 |
|
| 426 |
# command example view-log |
| 427 |
set -l opts "--pager=?,-h,--help" |
| 428 |
set -l C000 "$query '$opts' positional_contains 1 view-log && not $query '$opts' has_option -h --help --pager" |
| 429 |
complete -c $prog -n $C000 -l pager -f -a '(__fish_complete_command)' |
| 430 |
|
| 431 |
# vim: ft=fish ts=2 sts=2 sw=2 et |