mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 09:03:37 +08:00
d7ccc475cf
The external-commands-only completion was briefly added in 3.1.0 and removed in 3.1.1 (see #6798), which means we can remove some dead code. Maybe we should just remove __fish_complete_external_command - it could break users, but then again, we don't really have a way to stop people from starting to use this deprecated function. The underscores ought to communicate that this is function is private to fish but that is not enforced.
49 lines
1.6 KiB
Fish
49 lines
1.6 KiB
Fish
function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowing
|
|
# Pass --commandline to complete the remainder of the arguments instead of the commandline.
|
|
# Other args are considered flags to the supercommand that require an option.
|
|
|
|
# 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]
|
|
case --commandline
|
|
set subcommand $argv
|
|
set -e argv
|
|
break
|
|
end
|
|
end
|
|
set -l options_with_param $argv
|
|
|
|
if not string length -q -- $subcommand
|
|
set -l cmd (commandline -cop) (commandline -ct)
|
|
while set -q cmd[1]
|
|
set -l token $cmd[1]
|
|
set -e cmd[1]
|
|
if contains -- $token $options_with_param
|
|
set skip_next (math $skip_next + 1)
|
|
continue
|
|
end
|
|
switch $token
|
|
case '-*' '*=*'
|
|
continue
|
|
case '*'
|
|
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
|
|
end
|
|
end
|
|
end
|
|
|
|
printf "%s\n" (complete -C "$subcommand")
|
|
end
|