From: Frank Terbeck Date: Thu, 16 Aug 2007 16:48:32 +0000 (+0200) Subject: Let sudo-command-line() do something sensible on an empty buffer. X-Git-Tag: 0.3.22~2 X-Git-Url: http://git.grml.org/?a=commitdiff_plain;ds=sidebyside;h=b37e047d34cfcc875a7f9c1c8b55af438fc737bd;p=grml-etc-core.git Let sudo-command-line() do something sensible on an empty buffer. 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). --- diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 4f41604..ce010c3 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -508,10 +508,11 @@ fi # 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