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

Re: precommand modifiers and alias sudo="sudo "



On Wed, Dec 10, 2008 at 01:08:15PM +0100, Sebastian Stark wrote:
> I have set up an alias sudo="sudo " that enables use of aliases with sudo.
> But now precommand modifiers like "nocorrect" or "env"* stopped working.

I have a function that allows me to use aliases with sudo.  It handles
things like noglob and command, but just ignores nocorrect.  I don't use
env, so that's not currently handled.

alias sudo='noglob do_sudo '
function do_sudo
{
    integer glob=1
    local -a run
    run=( command sudo )
    if [[ $# -gt 1 && $1 = -u ]]; then
        run+=($1 $2)
        shift ; shift
    fi
    (($# == 0)) && 1=/bin/zsh
    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
}

..wayne..



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