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

Re: user-sensitive kill completion in conjunction with sudo



On Oct 7, 11:10pm, Matt Wozniski wrote:
}
} Is there some easy (or even difficult) way to modify this to handle
} the user 'kill' will be executed as?

This should do it, but see commentary caveats.

pids4kill() {
    local -a ps

    # This is using inside knowledge of the implementation.
    # Not guaranteed to work across upgrades, but likely to.
    if [[ $oldcontext = *:sudo:* ]]
    then
        # More inside knowledge:  Peek at the sudo options.
        # Also not guaranteed to work across upgrades.
        local u=$opt_args[-u]
        if [[ -n $u ]]
        then
            ps=(ps -u $u)
        else
            ps=(ps -u root)
        fi
    else
        ps=(ps -u $USER)
    fi
    $ps -o pid,%cpu,tty,cputime,cmd
}
zstyle ':completion:*:*:kill:*' command pids4kill



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