sudo.plugin.zsh 906 Bytes
Newer Older
dongweiming's avatar
dongweiming committed
1
2
3
4
# ------------------------------------------------------------------------------
# Description
# -----------
#
5
# sudo or sudoedit will be inserted before the command
dongweiming's avatar
dongweiming committed
6
7
8
9
10
11
12
13
14
15
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Dongweiming <ciici123@gmail.com>
#
# ------------------------------------------------------------------------------

sudo-command-line() {
16
    [[ -z $BUFFER ]] && zle up-history
Fabio Strozzi's avatar
Fabio Strozzi committed
17
18
    if [[ $BUFFER == sudo\ * ]]; then
        LBUFFER="${LBUFFER#sudo }"
19
20
21
22
23
24
    elif [[ $BUFFER == $EDITOR\ * ]]; then
        LBUFFER="${LBUFFER#$EDITOR }"
        LBUFFER="sudoedit $LBUFFER"
    elif [[ $BUFFER == sudoedit\ * ]]; then
        LBUFFER="${LBUFFER#sudoedit }"
        LBUFFER="$EDITOR $LBUFFER"
Fabio Strozzi's avatar
Fabio Strozzi committed
25
26
27
    else
        LBUFFER="sudo $LBUFFER"
    fi
dongweiming's avatar
dongweiming committed
28
29
30
31
}
zle -N sudo-command-line
# Defined shortcut keys: [Esc] [Esc]
bindkey "\e\e" sudo-command-line