2016-11-28 05:27:22 +00:00
|
|
|
function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowing
|
2019-11-05 09:56:03 +00:00
|
|
|
# How many non-option tokens we skip in the input commandline before completing the subcommand
|
|
|
|
# Usually 1; for ssh 2.
|
|
|
|
set -l skip_next 1
|
|
|
|
set -l subcommand
|
|
|
|
while string match -rq -- '^--[a-z]' $argv[1]
|
|
|
|
set -l arg $argv[1]
|
|
|
|
set -e argv[1]
|
|
|
|
switch $arg
|
|
|
|
case '--fcs-skip=*'
|
|
|
|
set skip_next (string split = -- $arg)[2]
|
2021-08-10 18:55:20 +00:00
|
|
|
case --commandline # --commandline means to use our arguments instead of the commandline.
|
2019-11-05 09:56:03 +00:00
|
|
|
set subcommand $argv
|
|
|
|
set -e argv
|
|
|
|
break
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
2019-11-05 09:56:03 +00:00
|
|
|
end
|
|
|
|
set -l options_with_param $argv
|
|
|
|
|
2019-11-16 06:50:54 +00:00
|
|
|
if not string length -q -- $subcommand
|
2024-01-22 06:42:45 +00:00
|
|
|
set -l cmd (commandline -cxp | string escape) (commandline -ct)
|
2019-11-05 09:56:03 +00:00
|
|
|
while set -q cmd[1]
|
|
|
|
set -l token $cmd[1]
|
|
|
|
set -e cmd[1]
|
|
|
|
if contains -- $token $options_with_param
|
2017-09-10 06:35:47 +00:00
|
|
|
set skip_next (math $skip_next + 1)
|
2016-11-28 05:27:22 +00:00
|
|
|
continue
|
|
|
|
end
|
2019-11-05 09:56:03 +00:00
|
|
|
switch $token
|
|
|
|
case '-*' '*=*'
|
|
|
|
continue
|
2016-11-28 05:27:22 +00:00
|
|
|
case '*'
|
2019-11-05 09:56:03 +00:00
|
|
|
if test $skip_next -gt 0
|
|
|
|
set skip_next (math $skip_next - 1)
|
|
|
|
continue
|
|
|
|
end
|
|
|
|
# found the start of our command
|
|
|
|
set subcommand $token $cmd
|
|
|
|
break
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-06 18:37:44 +00:00
|
|
|
printf "%s\n" (complete -C "$subcommand")
|
2006-02-08 09:20:05 +00:00
|
|
|
end
|