mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-14 05:02:48 +08:00
![Johannes Altmanninger](/assets/img/avatar_default.png)
Commit 798527d79a
(completions: fix double evaluation of tokenized
commandline, 2024-01-06) fixed some completions such as the "watchexec"
ones by adding "string escape" here:
set argv (commandline -opc | string escape) (commandline -ct)
This fixed double evaluation when we later call `complete -C"$argv"`.
Unfortunately -- searching for "complete -C" and
"__fish_complete_subcommand" -- it seems like that commit missed some
completions such as sudo. Fix them the same way.
Alternatively, we could defer expansion of those arguments (via
--tokens-raw), since the recursive call to completion will expand
them anyway, and we don't really need to know their value.
But there are (contrived) examples where we do want to expand first,
to correctly figure out where the subcommand starts:
sudo {-u,someuser} make ins
By definition, the tokens returned by `commandline -opc` do not
contain the token at cursor (which we're currently completing).
So the expansion should not hurt us. There is an edge case where
cartesian product expansion would produce too many results, and we
pass on the unexpanded input. In that case the extra escaping is very
unlikely to have negative effects.
Fixes # 11041
Closes # 11067
Co-authored-by: kerty <g.kabakov@inbox.ru>
37 lines
1.7 KiB
Fish
37 lines
1.7 KiB
Fish
# Completion for doas https://github.com/multiplexd/doas
|
|
# based on the sudo completions
|
|
#
|
|
|
|
function __fish_doas_print_remaining_args
|
|
set -l tokens (commandline -xpc | string escape) (commandline -ct)
|
|
set -e tokens[1]
|
|
# These are all the options mentioned in the man page for openbsd's "doas" (in that order).
|
|
set -l opts a= C= L n s u=
|
|
argparse -s $opts -- $tokens 2>/dev/null
|
|
# The remaining argv is the subcommand with all its options, which is what
|
|
# we want.
|
|
if test -n "$argv"
|
|
and not string match -qr '^-' $argv[1]
|
|
string join0 -- $argv
|
|
return 0
|
|
else
|
|
return 1
|
|
end
|
|
end
|
|
|
|
function __fish_complete_doas_subcommand
|
|
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
|
|
|
|
complete -c doas -n "not __fish_doas_print_remaining_args" -s a -d "Choose auth method on systems using /etc/login.conf"
|
|
complete -c doas -n "not __fish_doas_print_remaining_args" -s C -r -d "validate given config file and test it against given command"
|
|
complete -c doas -n "not __fish_doas_print_remaining_args" -s L -d "Clear persisted authorizations, then exit"
|
|
complete -c doas -n "not __fish_doas_print_remaining_args" -s n -d "Fail if doas would prompt for password"
|
|
complete -c doas -n "not __fish_doas_print_remaining_args" -s s -d "Execute the shell from SHELL or /etc/passwd"
|
|
complete -c doas -n "not __fish_doas_print_remaining_args" -s u -a "(__fish_complete_users)" -x -d "Execute the command as user. The default is root."
|
|
|
|
# Complete the command we are executing under doas
|
|
complete -c doas -x -a "(__fish_complete_doas_subcommand)"
|