mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-14 05:22:46 +08:00
Fix double expansion of tokenized command line
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>
This commit is contained in:
parent
1c11055241
commit
4024d82412
|
@ -3,7 +3,7 @@
|
|||
#
|
||||
|
||||
function __fish_doas_print_remaining_args
|
||||
set -l tokens (commandline -xpc) (commandline -ct)
|
||||
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=
|
||||
|
|
|
@ -62,7 +62,7 @@ end
|
|||
|
||||
# Get the text after all env arguments and variables, so we can complete it as a regular command
|
||||
function __fish_env_remaining_args -V is_gnu
|
||||
set -l argv (commandline -xpc) (commandline -ct)
|
||||
set -l argv (commandline -xpc | string escape) (commandline -ct)
|
||||
if set -q is_gnu[1]
|
||||
argparse -s i/ignore-environment u/unset= help version -- $argv 2>/dev/null
|
||||
or return 0
|
||||
|
|
|
@ -14,7 +14,7 @@ set -l ip_all_commands $ip_commands $ip_addr $ip_link $ip_neigh $ip_route $ip_ru
|
|||
|
||||
function __fish_ip_commandwords
|
||||
set -l skip 0
|
||||
set -l cmd (commandline -xpc)
|
||||
set -l cmd (commandline -xpc | string escape)
|
||||
# Remove the first word because it's "ip" or an alias for it
|
||||
set -e cmd[1]
|
||||
set -l have_command 0
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#
|
||||
|
||||
function __fish_sudo_print_remaining_args
|
||||
set -l tokens (commandline -xpc) (commandline -ct)
|
||||
set -l tokens (commandline -xpc | string escape) (commandline -ct)
|
||||
set -e tokens[1]
|
||||
# These are all the options mentioned in the man page for Todd Miller's "sudo.ws" sudo (in that order).
|
||||
# If any other implementation has different options, this should be harmless, since they shouldn't be used anyway.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
function __fish_complete_svn_diff --description 'Complete "svn diff" arguments'
|
||||
set -l cmdl (commandline -cxp)
|
||||
#set -l cmdl svn diff --diff-cmd diff --extensions '-a -b'
|
||||
set -l cmdl (commandline -cxp | string escape)
|
||||
set -l diff diff
|
||||
set -l args
|
||||
while set -q cmdl[1]
|
||||
|
|
|
@ -51,7 +51,7 @@ end
|
|||
# don't want to inherit all completions from git
|
||||
function __fish_complete_yadm_like_git
|
||||
# Remove the first word from the commandline because that is "yadm"
|
||||
set -l cmdline (commandline -xpc; commandline -ct)[2..-1]
|
||||
set -l cmdline (commandline -xpc | string escape; commandline -ct)[2..-1]
|
||||
|
||||
# `yadm gitconfig` is same as `git config`
|
||||
if __fish_seen_subcommand_from gitconfig
|
||||
|
|
Loading…
Reference in New Issue
Block a user