2019-07-03 18:57:23 +08:00
|
|
|
# RUN: %fish %s
|
2018-02-28 06:06:39 +08:00
|
|
|
function complete_test_alpha1; echo $argv; end
|
|
|
|
|
2018-02-27 11:21:46 +08: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 18:57:23 +08:00
|
|
|
# CHECK: complete_test_alpha1 arg1
|
2018-02-27 11:21:46 +08:00
|
|
|
complete -C'complete_test_alpha2 arg2 '
|
2019-07-03 18:57:23 +08:00
|
|
|
# CHECK: complete_test_alpha1 extra1 arg2
|
2018-02-27 11:21:46 +08:00
|
|
|
complete -C'complete_test_alpha3 arg3 '
|
2019-07-03 18:57:23 +08:00
|
|
|
# CHECK: complete_test_alpha1 extra1 extra2 arg3
|
2019-04-26 20:54:51 +08:00
|
|
|
# Works even with the argument as a separate token.
|
|
|
|
complete -C 'complete_test_alpha3 arg3 '
|
2019-07-03 18:57:23 +08:00
|
|
|
# CHECK: complete_test_alpha1 extra1 extra2 arg3
|
2018-02-28 06:06:39 +08:00
|
|
|
|
|
|
|
alias myalias1 'complete_test_alpha1 arg1'
|
|
|
|
alias myalias2='complete_test_alpha1 arg2'
|
|
|
|
|
|
|
|
myalias1 call1
|
|
|
|
myalias2 call2
|
2019-07-03 18:57:23 +08:00
|
|
|
# CHECK: arg1 call1
|
|
|
|
# CHECK: arg2 call2
|
2018-02-28 06:06:39 +08:00
|
|
|
complete -C'myalias1 call3 '
|
2019-01-17 23:43:24 +08:00
|
|
|
complete -C'myalias2 call3 '
|
2019-07-03 18:57:23 +08:00
|
|
|
# CHECK: complete_test_alpha1 arg1 call3
|
|
|
|
# CHECK: complete_test_alpha1 arg2 call3
|
2019-01-17 23:43:24 +08:00
|
|
|
|
|
|
|
# Ensure that commands can't wrap themselves - if this did,
|
|
|
|
# the completion would be executed a bunch of times.
|
|
|
|
function t --wraps t; echo t; end
|
|
|
|
complete -c t -fa '(t)'
|
|
|
|
complete -C't '
|
2019-07-03 18:57:23 +08:00
|
|
|
# CHECK: t
|
2019-05-31 01:12:49 +08:00
|
|
|
|
|
|
|
# Ensure file completion happens even though it was disabled above.
|
|
|
|
complete -c t -l fileoption -rF
|
2019-07-03 18:57:23 +08: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-20 06:01:09 +08: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-20 06:44:15 +08:00
|
|
|
# CHECK: complete {{.*}}
|
|
|
|
# CHECK: complete {{.*}}
|
|
|
|
# CHECK: complete {{.*}}
|
|
|
|
# CHECK: complete {{.*}}
|
|
|
|
# CHECK: complete {{.*}}
|
2019-10-03 13:55:52 +08: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 13:58:04 +08: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 18:49:56 +08: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 20:12:56 +08: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 20:32:26 +08: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 19:37:41 +08:00
|
|
|
|
|
|
|
complete -C'echo > /' | string length -q && echo ok
|
|
|
|
# CHECK: ok
|