Skip to content

Commit

Permalink
sudo: keep space before the command to ignore it in the history (ohmy…
Browse files Browse the repository at this point in the history
…zsh#9178)

Co-authored-by: Marc Cornellà <marc.cornella@live.com>
  • Loading branch information
daddeffe and mcornella committed Aug 23, 2020
1 parent c785db6 commit cd17aed
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugins/sudo/sudo.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 }"
Expand All @@ -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]
Expand Down

0 comments on commit cd17aed

Please sign in to comment.