Fix some issues in __fish_complete_subcommand.fish

Fix 'string length: Unknown option': add `--` before $subcommand

Fix count $subcommand always = 1 with `sudo` and `doas`:
give argv as array to __fish_complete_subcommand

[ci skip]
This commit is contained in:
Akatsuki 2019-11-16 14:50:54 +08:00 committed by Johannes Altmanninger
parent 330f1701d7
commit cb72a33e0c
4 changed files with 6 additions and 7 deletions

View File

@ -14,7 +14,7 @@ function __fish_doas_print_remaining_args
# we want.
if test -n "$argv"
and not string match -qr '^-' $argv[1]
echo $argv
string join0 -- $argv
return 0
else
return 1
@ -22,7 +22,7 @@ function __fish_doas_print_remaining_args
end
function __fish_complete_doas_subcommand
set -l args (__fish_doas_print_remaining_args)
set -l args (__fish_doas_print_remaining_args | string split0)
set -lx -a PATH /usr/local/sbin /sbin /usr/sbin
__fish_complete_subcommand --commandline $args
end

View File

@ -20,7 +20,7 @@ function __fish_sudo_print_remaining_args
# we want.
if test -n "$argv"
and not string match -qr '^-' $argv[1]
echo $argv
string join0 -- $argv
return 0
else
return 1
@ -32,7 +32,7 @@ function __fish_sudo_no_subcommand
end
function __fish_complete_sudo_subcommand
set -l args (__fish_sudo_print_remaining_args)
set -l args (__fish_sudo_print_remaining_args | string split0)
set -lx -a PATH /usr/local/sbin /sbin /usr/sbin
__fish_complete_subcommand --commandline $args
end

View File

@ -9,7 +9,7 @@ function __fish_clang_complete
# Don't hard-code the name of the clang binary
set -l clang (commandline -o)[1]
# first get the completions from clang, with the prefix separated from the value by a comma
$clang --autocomplete=(commandline -ct | string replace -- "$prefix" "$prefix,") 2>/dev/null |
$clang --autocomplete=(commandline -ct | string unescape | string replace -- "$prefix" "$prefix,") 2>/dev/null |
# and put it in a format that fish understands
string replace -r -- '^([^ ]+)\s*(.*)' "$prefix\$1\t\$2"
end

View File

@ -24,7 +24,7 @@ function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowin
end
set -l options_with_param $argv
if not string length -q $subcommand
if not string length -q -- $subcommand
set cmd (commandline -cop) (commandline -ct)
while set -q cmd[1]
set -l token $cmd[1]
@ -55,4 +55,3 @@ function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowin
end
end