diff options
author | daddeffe <daddef@gmail.com> | 2020-08-23 22:58:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-23 22:58:08 +0200 |
commit | cd17aed9e109692273b5c251414ee733cba704f2 (patch) | |
tree | ef70fad3ae15abc3088c8f276ab3196dd07d5de1 | |
parent | c785db621e8bdb9edb897cc7353fe87fb6e550b1 (diff) | |
download | zsh-cd17aed9e109692273b5c251414ee733cba704f2.tar.gz zsh-cd17aed9e109692273b5c251414ee733cba704f2.tar.bz2 zsh-cd17aed9e109692273b5c251414ee733cba704f2.zip |
sudo: keep space before the command to ignore it in the history (#9178)
Co-authored-by: Marc Cornellà <marc.cornella@live.com>
-rw-r--r-- | plugins/sudo/sudo.plugin.zsh | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/plugins/sudo/sudo.plugin.zsh b/plugins/sudo/sudo.plugin.zsh index 51579377d..b3749eff7 100644 --- a/plugins/sudo/sudo.plugin.zsh +++ b/plugins/sudo/sudo.plugin.zsh @@ -14,6 +14,14 @@ sudo-command-line() { [[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)" + + # Save beginning space + local WHITESPACE="" + if [[ ${LBUFFER:0:1} == " " ]] ; then + WHITESPACE=" " + LBUFFER="${LBUFFER:1}" + fi + if [[ -n $EDITOR && $BUFFER == $EDITOR\ * ]]; then if [[ ${#LBUFFER} -le ${#EDITOR} ]]; then RBUFFER=" ${BUFFER#$EDITOR }" @@ -38,6 +46,9 @@ sudo-command-line() { else LBUFFER="sudo $LBUFFER" fi + + # Preserve beginning space + LBUFFER="${WHITESPACE}${LBUFFER}" } zle -N sudo-command-line # Defined shortcut keys: [Esc] [Esc] |