2019-07-03 10:57:23 +00:00
|
|
|
# RUN: %fish %s
|
2020-01-13 19:34:22 +00:00
|
|
|
function complete_test_alpha1
|
|
|
|
echo $argv
|
|
|
|
end
|
2018-02-27 22:06:39 +00:00
|
|
|
|
2018-02-27 03:21:46 +00:00
|
|
|
complete -c complete_test_alpha1 --no-files -a '(commandline)'
|
|
|
|
complete -c complete_test_alpha2 --no-files -w 'complete_test_alpha1 extra1'
|
|
|
|
complete -c complete_test_alpha3 --no-files -w 'complete_test_alpha2 extra2'
|
|
|
|
|
|
|
|
complete -C'complete_test_alpha1 arg1 '
|
2019-07-03 10:57:23 +00:00
|
|
|
# CHECK: complete_test_alpha1 arg1
|
2018-02-27 03:21:46 +00:00
|
|
|
complete -C'complete_test_alpha2 arg2 '
|
2019-07-03 10:57:23 +00:00
|
|
|
# CHECK: complete_test_alpha1 extra1 arg2
|
2018-02-27 03:21:46 +00:00
|
|
|
complete -C'complete_test_alpha3 arg3 '
|
2019-07-03 10:57:23 +00:00
|
|
|
# CHECK: complete_test_alpha1 extra1 extra2 arg3
|
2019-04-26 12:54:51 +00:00
|
|
|
# Works even with the argument as a separate token.
|
|
|
|
complete -C 'complete_test_alpha3 arg3 '
|
2019-07-03 10:57:23 +00:00
|
|
|
# CHECK: complete_test_alpha1 extra1 extra2 arg3
|
2018-02-27 22:06:39 +00:00
|
|
|
|
|
|
|
alias myalias1 'complete_test_alpha1 arg1'
|
|
|
|
alias myalias2='complete_test_alpha1 arg2'
|
|
|
|
|
|
|
|
myalias1 call1
|
|
|
|
myalias2 call2
|
2019-07-03 10:57:23 +00:00
|
|
|
# CHECK: arg1 call1
|
|
|
|
# CHECK: arg2 call2
|
2018-02-27 22:06:39 +00:00
|
|
|
complete -C'myalias1 call3 '
|
2019-01-17 15:43:24 +00:00
|
|
|
complete -C'myalias2 call3 '
|
2019-07-03 10:57:23 +00:00
|
|
|
# CHECK: complete_test_alpha1 arg1 call3
|
|
|
|
# CHECK: complete_test_alpha1 arg2 call3
|
2019-01-17 15:43:24 +00:00
|
|
|
|
|
|
|
# Ensure that commands can't wrap themselves - if this did,
|
|
|
|
# the completion would be executed a bunch of times.
|
2020-01-13 19:34:22 +00:00
|
|
|
function t --wraps t
|
|
|
|
echo t
|
|
|
|
end
|
2019-01-17 15:43:24 +00:00
|
|
|
complete -c t -fa '(t)'
|
|
|
|
complete -C't '
|
2019-07-03 10:57:23 +00:00
|
|
|
# CHECK: t
|
2019-05-30 17:12:49 +00:00
|
|
|
|
|
|
|
# Ensure file completion happens even though it was disabled above.
|
|
|
|
complete -c t -l fileoption -rF
|
2019-07-03 10:57:23 +00:00
|
|
|
# Only match one file because I don't want to touch this any time we add a test file.
|
|
|
|
complete -C't --fileoption ' | string match bind.expect
|
|
|
|
# CHECK: bind.expect
|
2019-09-19 22:01:09 +00:00
|
|
|
|
|
|
|
# Make sure bare `complete` is reasonable,
|
|
|
|
complete -p '/complete test/beta1' -d 'desc, desc' -sZ
|
|
|
|
complete -c 'complete test beta2' -r -d 'desc \' desc2 [' -a 'foo bar'
|
|
|
|
complete -c 'complete_test_beta2' -x -n 'false' -A -o test
|
|
|
|
complete
|
|
|
|
|
|
|
|
# CHECK: complete --no-files -c complete_test_alpha1 -a '(commandline)'
|
|
|
|
# CHECK: complete --no-files -c complete_test_alpha2
|
|
|
|
# CHECK: complete --no-files -c complete_test_alpha3
|
|
|
|
# CHECK: complete --force-files -c t -l fileoption
|
|
|
|
# CHECK: complete --no-files -c t -a '(t)'
|
|
|
|
# CHECK: complete -p '/complete test/beta1' -s Z -d 'desc, desc'
|
|
|
|
# CHECK: complete --requires-param -c 'complete test beta2' -d desc\ \'\ desc2\ \[ -a 'foo bar'
|
|
|
|
# CHECK: complete --exclusive -c complete_test_beta2 -o test -n false
|
2019-09-19 22:44:15 +00:00
|
|
|
# CHECK: complete {{.*}}
|
|
|
|
# CHECK: complete {{.*}}
|
|
|
|
# CHECK: complete {{.*}}
|
|
|
|
# CHECK: complete {{.*}}
|
|
|
|
# CHECK: complete {{.*}}
|
2019-10-03 05:55:52 +00:00
|
|
|
|
|
|
|
# Recursive calls to complete (see #3474)
|
|
|
|
complete -c complete_test_recurse1 -xa '(echo recursing 1>&2; complete -C"complete_test_recurse1 ")'
|
|
|
|
complete -C'complete_test_recurse1 '
|
|
|
|
# CHECKERR: recursing
|
2019-10-03 05:58:04 +00:00
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
|
|
|
# CHECKERR: recursing
|
2019-10-06 10:49:56 +00:00
|
|
|
# CHECKERR: complete: maximum recursion depth reached
|
Completion: complete argument to last of a group of short options
Consider a group of short options, like -xzPARAM, where x and z are options and z takes an argument.
This commit enables completion of the argument to the last option (z), both within the same
token (-xzP) or in the next one (-xz P).
complete -C'-xz' will complete only parameters to z.
complete -C'-xz ' will complete only parameters to z if z requires a parameter
otherwise, it will also complete non-option parameters
To do so this implements a heuristic to differentiate such strings from single long options. To
detect whether our token contains some short options, we only require the first character after the
dash (here x) to be an option. Previously, all characters had to be short options. The last option
in our example is z. Everything after the last option is assumed to be a parameter to the last
option.
Assume there is also a single long option -x-foo, then complete -C'-x' will suggest both -x-foo and
-xy. However, when the single option x requires an argument, this will not suggest -x-foo.
However, I assume this will almost never happen in practise since completions very rarely mix
short and single long options.
Fixes #332
2019-09-10 12:12:56 +00:00
|
|
|
|
|
|
|
# short options
|
|
|
|
complete -c foo -f -a non-option-argument
|
|
|
|
complete -c foo -f --short-option x
|
|
|
|
complete -c foo -f --short-option y -a 'ARGY'
|
|
|
|
complete -c foo -f --short-option z -a 'ARGZ' -r
|
|
|
|
complete -c foo -f --old-option single-long-ending-in-z
|
|
|
|
complete -c foo -f --old-option x-single-long
|
|
|
|
complete -c foo -f --old-option y-single-long
|
|
|
|
complete -c foo -f --old-option z-single-long
|
|
|
|
complete -c foo -f --long-option x-long -a 'ARGLONG'
|
|
|
|
# Make sure that arguments of concatenated short options are expanded (#332)
|
|
|
|
complete -C'foo -xy'
|
|
|
|
# CHECK: -xyARGY
|
|
|
|
# CHECK: -xyz
|
|
|
|
# A required parameter means we don't want more short options.
|
|
|
|
complete -C'foo -yz'
|
|
|
|
# CHECK: -yzARGZ
|
|
|
|
# Required parameter with space: complete only the parameter (no non-option arguments).
|
|
|
|
complete -C'foo -xz '
|
|
|
|
# CHECK: ARGZ
|
|
|
|
# Optional parameter with space: complete only non-option arguments.
|
|
|
|
complete -C'foo -xy '
|
|
|
|
# CHECK: non-option-argument
|
|
|
|
complete -C'foo -single-long-ending-in-z'
|
|
|
|
# CHECK: -single-long-ending-in-z
|
|
|
|
complete -C'foo -single-long-ending-in-z '
|
|
|
|
# CHECK: non-option-argument
|
|
|
|
# CHECK: -x-single-long
|
|
|
|
complete -C'foo -x' | string match -- -x-single-long
|
|
|
|
# CHECK: -y-single-long
|
|
|
|
complete -C'foo -y' | string match -- -y-single-long
|
|
|
|
# This does NOT suggest -z-single-long, but will probably not occur in practise.
|
|
|
|
# CHECK: -zARGZ
|
|
|
|
complete -C'foo -z'
|
|
|
|
|
2019-10-29 12:32:26 +00:00
|
|
|
|
|
|
|
# Builtins (with subcommands; #2705)
|
|
|
|
complete -c complete_test_subcommand -n 'test (commandline -op)[1] = complete_test_subcommand' -xa 'ok'
|
|
|
|
complete -C'not complete_test_subcommand '
|
|
|
|
# CHECK: ok
|
|
|
|
complete -C'echo; and complete_test_subcommand '
|
|
|
|
# CHECK: ok
|
|
|
|
complete -C'or complete_test_subcommand '
|
|
|
|
# CHECK: ok
|
|
|
|
complete -C'echo && command complete_test_subcommand '
|
|
|
|
# CHECK: ok
|
|
|
|
complete -C'echo || exec complete_test_subcommand '
|
|
|
|
# CHECK: ok
|
|
|
|
complete -C'echo | builtin complete_test_subcommand '
|
|
|
|
# CHECK: ok
|
|
|
|
complete -C'echo & complete_test_subcommand '
|
|
|
|
# CHECK: ok
|
|
|
|
complete -C'if while begin begin complete_test_subcommand '
|
|
|
|
# CHECK: ok
|
|
|
|
|
|
|
|
complete -C'for _ in ' | string collect >&- && echo completed some files
|
|
|
|
# CHECK: completed some files
|
|
|
|
|
|
|
|
# function; #5415
|
|
|
|
complete -C'function : --arg'
|
|
|
|
# CHECK: --argument-names {{.*}}
|
2019-12-16 11:37:41 +00:00
|
|
|
|
|
|
|
complete -C'echo > /' | string length -q && echo ok
|
|
|
|
# CHECK: ok
|
2020-01-08 16:53:46 +00:00
|
|
|
|
|
|
|
function some_function
|
2020-01-13 19:34:22 +00:00
|
|
|
echo line1
|
|
|
|
echo line2
|
2020-01-08 16:53:46 +00:00
|
|
|
end
|
|
|
|
complete -c complete_test_function_desc -xa '(complete -Csome_function)'
|
|
|
|
complete -C'complete_test_function_desc ' | count
|
|
|
|
# CHECK: 1
|