2016-11-28 13:27:22 +08:00
|
|
|
function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowing
|
2019-11-05 17:56:03 +08: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-11 02:55:20 +08:00
|
|
|
case --commandline # --commandline means to use our arguments instead of the commandline.
|
2019-11-05 17:56:03 +08:00
|
|
|
set subcommand $argv
|
|
|
|
set -e argv
|
|
|
|
break
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
2019-11-05 17:56:03 +08:00
|
|
|
end
|
|
|
|
set -l options_with_param $argv
|
|
|
|
|
2019-11-16 14:50:54 +08:00
|
|
|
if not string length -q -- $subcommand
|
2024-01-22 14:42:45 +08:00
|
|
|
set -l cmd (commandline -cxp | string escape) (commandline -ct)
|
2019-11-05 17:56:03 +08:00
|
|
|
while set -q cmd[1]
|
|
|
|
set -l token $cmd[1]
|
|
|
|
set -e cmd[1]
|
|
|
|
if contains -- $token $options_with_param
|
2017-09-10 14:35:47 +08:00
|
|
|
set skip_next (math $skip_next + 1)
|
2016-11-28 13:27:22 +08:00
|
|
|
continue
|
|
|
|
end
|
2019-11-05 17:56:03 +08:00
|
|
|
switch $token
|
|
|
|
case '-*' '*=*'
|
|
|
|
continue
|
2016-11-28 13:27:22 +08:00
|
|
|
case '*'
|
2019-11-05 17:56:03 +08: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 13:27:22 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-07 02:37:44 +08:00
|
|
|
printf "%s\n" (complete -C "$subcommand")
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|