2017-11-16 00:24:10 +00:00
|
|
|
# Source: https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/sudo/sudo.plugin.zsh
|
|
|
|
|
|
|
|
sudo-command-line() {
|
|
|
|
[[ -z $BUFFER ]] && zle up-history
|
|
|
|
if [[ $BUFFER == sudo\ * ]]; then
|
|
|
|
LBUFFER="${LBUFFER#sudo }"
|
2017-11-16 00:30:45 +00:00
|
|
|
elif [[ $BUFFER == $EDITOR\ * ]] || [[ $BUFFER == vi\ * ]]; then
|
2017-11-16 00:24:10 +00:00
|
|
|
LBUFFER="${LBUFFER#$EDITOR }"
|
2017-11-16 00:30:45 +00:00
|
|
|
LBUFFER="${LBUFFER#vi }"
|
|
|
|
LBUFFER="svi $LBUFFER"
|
|
|
|
elif [[ $BUFFER == sudoedit\ * ]] || [[ $BUFFER == svi\ * ]]; then
|
2017-11-16 00:24:10 +00:00
|
|
|
LBUFFER="${LBUFFER#sudoedit }"
|
2017-11-16 00:30:45 +00:00
|
|
|
LBUFFER="${LBUFFER#svi }"
|
2017-11-16 00:24:10 +00:00
|
|
|
LBUFFER="$EDITOR $LBUFFER"
|
|
|
|
else
|
|
|
|
LBUFFER="sudo $LBUFFER"
|
|
|
|
fi
|
2017-11-16 00:43:14 +00:00
|
|
|
|
|
|
|
_zsh_highlight
|
2017-11-16 00:24:10 +00:00
|
|
|
}
|
|
|
|
zle -N sudo-command-line
|
|
|
|
# Defined shortcut keys: [Esc] [Esc]
|
|
|
|
bindkey "\e\e" sudo-command-line
|