Complete empty subcomands consistently

If the command is empty, try to complete starting from the empty command
instead of the whole commandline.
This commit is contained in:
Johannes Altmanninger 2019-11-03 23:55:54 +01:00
parent 12e783e30e
commit 36693e4391
10 changed files with 14 additions and 12 deletions

View File

@ -24,7 +24,7 @@ end
function __fish_complete_doas_subcommand
set -l args (__fish_doas_print_remaining_args)
set -lx -a PATH /usr/local/sbin /sbin /usr/sbin
complete -C"$args"
complete -C "$args"
end
complete -c doas -n "not __fish_doas_print_remaining_args" -s a -d "Choose auth method on systems using /etc/login.conf"

View File

@ -2,7 +2,7 @@
complete -x -c su -a "(__fish_complete_users)"
complete -c su -s l -l login -d "Make login shell"
complete -r -c su -s c -l command -d "Pass command to shell" -xa "(complete -C(commandline -ct))"
complete -c su -s c -l command -d "Pass command to shell" -xa "(__fish_complete_external_command)"
complete -c su -s f -l fast -d "Pass -f to the shell"
complete -c su -s m -l preserve_environment -d "Preserve environment"
complete -c su -s p -d "Preserve environment"

View File

@ -34,7 +34,7 @@ end
function __fish_complete_sudo_subcommand
set -l args (__fish_sudo_print_remaining_args)
set -lx -a PATH /usr/local/sbin /sbin /usr/sbin
complete -C"$args"
complete -C "$args"
end
# All these options should be valid for GNU and OSX sudo

View File

@ -172,7 +172,7 @@ for cmd in $blame $diff $log $merge
end
for cmd in $cleanup $merge $switch $update
_svn_cmpl_ $cmd -l diff3-cmd -d 'Use as merge command' -xa "(complete -C(commandline -ct))"
_svn_cmpl_ $cmd -l diff3-cmd -d 'Use as merge command' -xa "(__fish_complete_external_command)"
end
for cmd in $blame $info $list $log $stat
@ -193,7 +193,7 @@ end
for cmd in $diff $log
_svn_cmpl_ $cmd -l internal-diff -d 'Override diff-cmd specified in config file'
_svn_cmpl_ $cmd -l diff-cmd -d 'Use external diff command' -xa "(complete -C(commandline -ct))"
_svn_cmpl_ $cmd -l diff-cmd -d 'Use external diff command' -xa "(__fish_complete_external_command)"
end
for cmd in $add $import

View File

@ -10,4 +10,4 @@ complete -c type -s q -l quiet -d "Suppress output"
complete -c type -a "(builtin -n)" -d "Builtin"
complete -c type -a "(functions -n)" -d "Function"
complete -c type -a "(complete -C(commandline -ct))" -x
complete -c type -a "(__fish_complete_command)" -x

View File

@ -16,4 +16,4 @@ else # OSX
complete -c which -s s -d "Print no output, only return 0 if found"
end
complete -c which -a "(complete -C(commandline -ct))" -x
complete -c which -a "(__fish_complete_external_command)" -x

View File

@ -98,7 +98,7 @@ complete -c xterm -o wc -d 'Use wide characters'
complete -c xterm -o wf -d 'Wait the first time for the window to be mapped'
complete -c xterm -o Sccn -d 'Use as input/output channel for an existing program'
complete -c xterm -s e -a "(complete -C(commandline -ct))" -x -d 'Run program in xterm'
complete -c xterm -s e -a "(__fish_complete_external_command)" -x -d 'Run program in xterm'
complete -r -c xterm -o bcf -d 'Blinking cursor will be off for that many milliseconds'
complete -r -c xterm -o bcn -d 'Blinking cursor will be on for that many milliseconds'

View File

@ -3,8 +3,10 @@ function __fish_complete_command --description 'Complete using all available com
switch $ctoken
case '*=*'
set ctoken (string split "=" -- $ctoken)
printf '%s\n' $ctoken[1]=(complete -C$ctoken[2])
printf '%s\n' $ctoken[1]=(complete -C "$ctoken[2]")
case '-*' # do not try to complete options as commands
return
case '*'
complete -C$ctoken
complete -C "$ctoken"
end
end

View File

@ -1,3 +1,3 @@
function __fish_complete_external_command
command find $PATH/ -maxdepth 1 -perm +u+x 2>&- | string match -r '[^/]*$'
command find $PATH/ -maxdepth 1 -perm -u+x 2>&- | string match -r '[^/]*$'
end

View File

@ -39,7 +39,7 @@ function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowin
end
end
printf "%s\n" (complete -C$res)
printf "%s\n" (complete -C "$res")
end