summaryrefslogtreecommitdiff
path: root/plugins/sudo/sudo.plugin.zsh
diff options
context:
space:
mode:
authorMDHD <MDHD.Yee@outlook.com>2020-07-06 10:13:49 -0500
committerGitHub <noreply@github.com>2020-07-06 17:13:49 +0200
commitfd9781b4c7036a3ef0a62744b9ecae327f9f2f24 (patch)
treef7e7c640a6c34bd6abf15259e17d58f921de312f /plugins/sudo/sudo.plugin.zsh
parenta8fee4036be264bd21ddf7fbe35f2a2e40eed412 (diff)
downloadzsh-fd9781b4c7036a3ef0a62744b9ecae327f9f2f24.tar.gz
zsh-fd9781b4c7036a3ef0a62744b9ecae327f9f2f24.tar.bz2
zsh-fd9781b4c7036a3ef0a62744b9ecae327f9f2f24.zip
sudo: make the behavior more in line with expectations (#9047)
Diffstat (limited to 'plugins/sudo/sudo.plugin.zsh')
-rw-r--r--plugins/sudo/sudo.plugin.zsh29
1 files changed, 21 insertions, 8 deletions
diff --git a/plugins/sudo/sudo.plugin.zsh b/plugins/sudo/sudo.plugin.zsh
index f405b025f..51579377d 100644
--- a/plugins/sudo/sudo.plugin.zsh
+++ b/plugins/sudo/sudo.plugin.zsh
@@ -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