From b37e047d34cfcc875a7f9c1c8b55af438fc737bd Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Thu, 16 Aug 2007 18:48:32 +0200 Subject: [PATCH] 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). --- etc/zsh/zshrc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 -- 2.1.4