When the buffer is empty, assume that the user wants to rerun the previous
command, prepended by 'sudo '. Also changed _sudo-command-line() to
sudo-command-line(). Per convention functions starting with underscore are
usually completion widgets (and it's really not needed here).
# zle -N mquote && bindkey '^q' mquote
# run command line as user root via sudo:
- _sudo-command-line() {
- [[ $BUFFER != sudo\ * ]] && LBUFFER="sudo $LBUFFER"
+ sudo-command-line() {
+ [[ -z $BUFFER ]] && zle up-history
+ [[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
}
- zle -N sudo-command-line _sudo-command-line
+ zle -N sudo-command-line
#k# Put the current command line into a \kbd{sudo} call
bindkey "^Os" sudo-command-line