Unverified Commit cd17aed9 authored by daddeffe's avatar daddeffe Committed by GitHub
Browse files

sudo: keep space before the command to ignore it in the history (#9178)


Co-authored-by: default avatarMarc Cornellà <marc.cornella@live.com>
parent c785db62
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
sudo-command-line() { sudo-command-line() {
[[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)" [[ -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 [[ -n $EDITOR && $BUFFER == $EDITOR\ * ]]; then
if [[ ${#LBUFFER} -le ${#EDITOR} ]]; then if [[ ${#LBUFFER} -le ${#EDITOR} ]]; then
RBUFFER=" ${BUFFER#$EDITOR }" RBUFFER=" ${BUFFER#$EDITOR }"
...@@ -38,6 +46,9 @@ sudo-command-line() { ...@@ -38,6 +46,9 @@ sudo-command-line() {
else else
LBUFFER="sudo $LBUFFER" LBUFFER="sudo $LBUFFER"
fi fi
# Preserve beginning space
LBUFFER="${WHITESPACE}${LBUFFER}"
} }
zle -N sudo-command-line zle -N sudo-command-line
# Defined shortcut keys: [Esc] [Esc] # Defined shortcut keys: [Esc] [Esc]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment