mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-22 05:40:08 +00:00
sudo: make the behavior more in line with expectations (#9047)
This commit is contained in:
parent
a8fee4036b
commit
fd9781b4c7
1 changed files with 21 additions and 8 deletions
|
@ -13,15 +13,28 @@
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
sudo-command-line() {
|
sudo-command-line() {
|
||||||
[[ -z $BUFFER ]] && zle up-history
|
[[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)"
|
||||||
if [[ $BUFFER == sudo\ * ]]; then
|
if [[ -n $EDITOR && $BUFFER == $EDITOR\ * ]]; then
|
||||||
LBUFFER="${LBUFFER#sudo }"
|
if [[ ${#LBUFFER} -le ${#EDITOR} ]]; then
|
||||||
elif [[ $BUFFER == $EDITOR\ * ]]; then
|
RBUFFER=" ${BUFFER#$EDITOR }"
|
||||||
LBUFFER="${LBUFFER#$EDITOR }"
|
LBUFFER="sudoedit"
|
||||||
LBUFFER="sudoedit $LBUFFER"
|
else
|
||||||
|
LBUFFER="sudoedit ${LBUFFER#$EDITOR }"
|
||||||
|
fi
|
||||||
elif [[ $BUFFER == sudoedit\ * ]]; then
|
elif [[ $BUFFER == sudoedit\ * ]]; then
|
||||||
LBUFFER="${LBUFFER#sudoedit }"
|
if [[ ${#LBUFFER} -le 8 ]]; then
|
||||||
LBUFFER="$EDITOR $LBUFFER"
|
RBUFFER=" ${BUFFER#sudoedit }"
|
||||||
|
LBUFFER="$EDITOR"
|
||||||
|
else
|
||||||
|
LBUFFER="$EDITOR ${LBUFFER#sudoedit }"
|
||||||
|
fi
|
||||||
|
elif [[ $BUFFER == sudo\ * ]]; then
|
||||||
|
if [[ ${#LBUFFER} -le 4 ]]; then
|
||||||
|
RBUFFER="${BUFFER#sudo }"
|
||||||
|
LBUFFER=""
|
||||||
|
else
|
||||||
|
LBUFFER="${LBUFFER#sudo }"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
LBUFFER="sudo $LBUFFER"
|
LBUFFER="sudo $LBUFFER"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue