1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-27 16:20:07 +00:00

do_sudo: new sudo alias to handle alias expansion

This commit is contained in:
Frederick Zhang 2019-09-21 16:14:31 +10:00
parent 3c209b00d6
commit d05feb1f8e
No known key found for this signature in database
GPG key ID: 980A192C361BE1AE
2 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# `do_sudo` plugin
This plugin provides a sudo wrapper that handles alias expansion and avoids
being broken by `nocorrect` `noglob` from other aliases.
Modified from the script by [Wayne Davison](https://www.zsh.org/mla/users/2008/msg01229.html).

View file

@ -0,0 +1,27 @@
if [[ "$ENABLE_CORRECTION" == "true" ]]; then
alias sudo='nocorrect noglob _do_sudo '
else
alias sudo='noglob _do_sudo '
fi
function _do_sudo() {
integer glob=1
local -a run
run=( command sudo )
while (($#)); do
case "$1" in
command|exec|-) shift; break ;;
nocorrect) shift ;;
noglob) glob=0; shift ;;
*) break ;;
esac
done
if ((glob)); then
PATH="/sbin:/usr/sbin:/usr/local/sbin:$PATH" $run $~==*
else
PATH="/sbin:/usr/sbin:/usr/local/sbin:$PATH" $run $==*
fi
}
command -v _sudo >/dev/null 2>&1
[[ $? -eq 0 ]] && compdef _sudo '_do_sudo'