zsh-workers
 help / color / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: sudo autocompletion
Date: Mon, 10 Feb 2020 19:20:33 +0000
Message-ID: <20200210192033.1bae83dc@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <D0BDD1BB-192E-4D50-A0D2-0BB54388B9B9@dana.is>

dana wrote on Mon, 10 Feb 2020 11:13 -0600:
> +++ b/Completion/Unix/Command/_sudo
> @@ -54,6 +54,18 @@ else
> +  # 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 ||

Might the user have set the command-path style in this context to
an empty value (zero strings, which would count as false)?

> +  zstyle -e ":completion:${curcontext%:}:*" command-path \
> +    'reply=( $path ${path/%\/bin//sbin} )'

Could this style setting shadow a style the user had set explicitly?
(e.g., because the pattern here is more specific than the pattern the
user has set)

As an alternative, _sudo could set _comp_command_path=( $path
$path/%\/bin//sbin ) and then _command_names could use that value if
the style isn't set then.  The parameter would be made local by
_main_complete.  This is similar to how, say, $precommands is handled.

HTH,

Daniel
[who was going to add this to zsh-sensible, but prefers fixing this
in zsh.git if possible :)]

  parent reply index

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <912d22db-8a8f-90f2-6738-f9f395994dcb@gmail.com>
     [not found] ` <CAN=4vMqvzUTZ7bBLcbTzi-pKAVEP1xDbq=f5pLAxmffxUjTszQ@mail.gmail.com>
     [not found]   ` <1770be62-54d8-70a6-8b05-cfc98faa9b9f@gmail.com>
     [not found]     ` <20200210030219.527a3ccf@tarpaulin.shahaf.local2>
     [not found]       ` <ADE72275-1311-44BE-9B1D-5E617E3D9F94@gmail.com>
2020-02-10 17:13         ` dana
2020-02-10 17:40           ` Peter Stephenson
2020-02-10 18:57             ` dana
2020-02-10 19:20           ` Daniel Shahaf [this message]
2020-02-11 10:12             ` Oliver Kiddle
2020-02-11 10:28               ` Setting/Querying cache-policy (was: Re: sudo autocompletion) Daniel Shahaf
2020-02-12 16:51                 ` dana
2020-02-13  1:21               ` sudo autocompletion dana
2020-02-13  1:29                 ` Bart Schaefer
2020-02-15 22:22                 ` Andrey Butirsky
2020-02-15 22:48                   ` dana
2020-02-10 22:05           ` Andrey Butirsky
2020-02-10 23:02             ` dana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200210192033.1bae83dc@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git