summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaddeffe <daddef@gmail.com>2020-08-23 22:58:08 +0200
committerGitHub <noreply@github.com>2020-08-23 22:58:08 +0200
commitcd17aed9e109692273b5c251414ee733cba704f2 (patch)
treeef70fad3ae15abc3088c8f276ab3196dd07d5de1
parentc785db621e8bdb9edb897cc7353fe87fb6e550b1 (diff)
downloadzsh-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.zsh11
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]