mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-18 11:50:07 +00:00
sudo: keep space before the command to ignore it in the history (#9178)
Co-authored-by: Marc Cornellà <marc.cornella@live.com>
This commit is contained in:
parent
c785db621e
commit
cd17aed9e1
1 changed files with 11 additions and 0 deletions
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue