Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: sudo autocompletion



On 10.02.2020 20:13, dana wrote:
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

Didn't see all the file, but probably 'su' and variants need something similar also?

One of the "solutions" (https://forums.gentoo.org/viewtopic-p-7978544.html?sid=fd1853347362adf53e40a5a0320030a8#7978544):

|[[ $UID -eq 0 ]] || () {||
||        local i||
||        local -T SUDO_PATH sudo_path||
||        local -U sudo_path=($path {,/usr{,/local}}/sbin(N-/))||
||
||        for i in su{,do}; do||
||                zstyle ":completion:*:$i:*" environ PATH="$SUDO_PATH"||
||        done||
||}|




Messages sorted by: Reverse Date, Date, Thread, Author