From 557234e352aed58726244fb786619f81b42c0e98 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Fri, 18 Oct 2019 21:41:39 +1100 Subject: [PATCH] do not resolve command to absolute path it breaks commands e.g. sudo -u http echo foobar as http is both a command (httpie) and a user/group (httpd) in my system --- plugins/do_sudo/do_sudo.plugin.zsh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/do_sudo/do_sudo.plugin.zsh b/plugins/do_sudo/do_sudo.plugin.zsh index 73a17061e..85ca2d853 100644 --- a/plugins/do_sudo/do_sudo.plugin.zsh +++ b/plugins/do_sudo/do_sudo.plugin.zsh @@ -17,14 +17,10 @@ function _do_sudo() { noglob) __do_sudo_glob=0; shift ;; *) cmd_alias="$(command -v 2>/dev/null -- "$1")" - if [[ "$?" -eq 0 ]]; then - if [[ "$cmd_alias" == 'alias'* ]] && [[ -z "$__do_sudo_expanded["$1"]" ]]; then - __do_sudo_expanded["$1"]=1 - IFS=' ' read -A cmd_alias_arr <<< "$(sed -e "s/[^=]*=//" -e "s/^'//" -e "s/'$//" <<< "$cmd_alias")" - args+=( "${cmd_alias_arr[@]}" ) - else - args+=( "$(sed "s/[^=]*=//" <<< "$(hash -v 2>/dev/null -- "$1")")" ) - fi + if [[ "$?" -eq 0 ]] && [[ "$cmd_alias" == 'alias'* ]] && [[ -z "$__do_sudo_expanded["$1"]" ]]; then + __do_sudo_expanded["$1"]=1 + IFS=' ' read -A cmd_alias_arr <<< "$(sed -e "s/[^=]*=//" -e "s/^'//" -e "s/'$//" <<< "$cmd_alias")" + args+=( "${cmd_alias_arr[@]}" ) shift break else