1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-21 21:30:09 +00:00

sudo: make the behavior more in line with expectations (#9047)

This commit is contained in:
MDHD 2020-07-06 10:13:49 -05:00 committed by GitHub
parent a8fee4036b
commit fd9781b4c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,15 +13,28 @@
# ------------------------------------------------------------------------------
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER == sudo\ * ]]; then
LBUFFER="${LBUFFER#sudo }"
elif [[ $BUFFER == $EDITOR\ * ]]; then
LBUFFER="${LBUFFER#$EDITOR }"
LBUFFER="sudoedit $LBUFFER"
[[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)"
if [[ -n $EDITOR && $BUFFER == $EDITOR\ * ]]; then
if [[ ${#LBUFFER} -le ${#EDITOR} ]]; then
RBUFFER=" ${BUFFER#$EDITOR }"
LBUFFER="sudoedit"
else
LBUFFER="sudoedit ${LBUFFER#$EDITOR }"
fi
elif [[ $BUFFER == sudoedit\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="$EDITOR $LBUFFER"
if [[ ${#LBUFFER} -le 8 ]]; then
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
LBUFFER="sudo $LBUFFER"
fi