Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: sudo autocompletion
- X-seq: zsh-workers 45410
- From: dana <dana@xxxxxxx>
- To: Andrey <butirsky@xxxxxxxxx>
- Subject: Re: sudo autocompletion
- Date: Mon, 10 Feb 2020 11:13:52 -0600
- Cc: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- In-reply-to: <ADE72275-1311-44BE-9B1D-5E617E3D9F94@gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <912d22db-8a8f-90f2-6738-f9f395994dcb@gmail.com> <CAN=4vMqvzUTZ7bBLcbTzi-pKAVEP1xDbq=f5pLAxmffxUjTszQ@mail.gmail.com> <1770be62-54d8-70a6-8b05-cfc98faa9b9f@gmail.com> <20200210030219.527a3ccf@tarpaulin.shahaf.local2> <ADE72275-1311-44BE-9B1D-5E617E3D9F94@gmail.com>
On 10 Feb 2020, at 01:52, Andrey <butirsky@xxxxxxxxx> wrote:
> Thanks, will try it. How about to include it in distribution by default?
Would this be too cheeky?
There's not much precedent for this sort of thing (just cache-policy), but i
don't think it'd cause any issues, aside from showing too many commands in
some uncommon cases...?
(Moved to -workers)
dana
diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo
index 41e32cbae..52b212176 100644
--- a/Completion/Unix/Command/_sudo
+++ b/Completion/Unix/Command/_sudo
@@ -54,6 +54,18 @@ else
'(-)1:command: _command_names -e'
'*::arguments:{ _comp_priv_prefix=( $cmd -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }'
)
+
+ # By default, _command_names uses the current PATH to complete commands. This
+ # doesn't necessarily make sense for sudo on systems that use its secure_path
+ # feature -- a common issue is that /**/sbin appear in secure_path but not in
+ # unprivileged users' PATHs. Ideally we could parse the correct value out of
+ # `sudo -l`, but since that requires a password it won't work half the time.
+ # To do the right thing in the most common cases, we'll simply ensure that the
+ # sbin variants always appear in the default command-path (bash-completion's
+ # _sudo does something similar)
+ zstyle -t ":completion:${curcontext}:" command-path ||
+ zstyle -e ":completion:${curcontext%:}:*" command-path \
+ 'reply=( $path ${path/%\/bin//sbin} )'
fi
_arguments -s -S $args
Messages sorted by:
Reverse Date,
Date,
Thread,
Author