-
Notifications
You must be signed in to change notification settings - Fork 1
/
sudo.plugin.zsh
33 lines (32 loc) · 995 Bytes
/
sudo.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# ------------------------------------------------------------------------------
# Description
# -----------
#
# sudo will be inserted before the command
# ** Copied from oh-my-zsh ***
# - https://github.com/ohmyzsh/ohmyzsh/plugins/sudo
# - Modified to stop using sudoedit
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Dongweiming <[email protected]>
#
# ------------------------------------------------------------------------------
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER == sudo\ * ]]; then
LBUFFER="${LBUFFER#sudo }"
elif [[ $BUFFER == sudoedit\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="$EDITOR $LBUFFER"
else
LBUFFER="sudo $LBUFFER"
fi
}
zle -N sudo-command-line
# Defined shortcut keys: [Esc] [Esc]
bindkey -M emacs '\e\e' sudo-command-line
bindkey -M vicmd '\e\e' sudo-command-line
bindkey -M viins '\e\e' sudo-command-line