Let sudo-command-line() do something sensible on an empty buffer.
authorFrank Terbeck <ft@grml.org>
Thu, 16 Aug 2007 16:48:32 +0000 (18:48 +0200)
committerFrank Terbeck <ft@grml.org>
Thu, 16 Aug 2007 16:48:32 +0000 (18:48 +0200)
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).

etc/zsh/zshrc

index 4f41604..ce010c3 100644 (file)
@@ -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