zsh-grawlinson/plugins/sudo

21 lines
578 B
Bash

# sudo will be inserted before the current command
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER == sudo\ * ]]; then
LBUFFER="${LBUFFER#sudo }"
elif [[ $BUFFER == $EDITOR\ * ]]; then
LBUFFER="${LBUFFER#$EDITOR }"
LBUFFER="sudoedit $LBUFFER"
elif [[ $BUFFER == sudoedit\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="$EDITOR $LBUFFER"
else
LBUFFER="sudo $LBUFFER"
fi
}
zle -N sudo-command-line
# defined shortcut keys: [Esc] [Esc]
bindkey "\e\e" sudo-command-line
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2