mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-21 11:51:57 +00:00
33 lines
999 B
Bash
33 lines
999 B
Bash
# ------------------------------------------------------------------------------
|
|
# Description
|
|
# -----------
|
|
#
|
|
# sudo or sudoedit will be inserted before the command
|
|
#
|
|
# ------------------------------------------------------------------------------
|
|
# Authors
|
|
# -------
|
|
#
|
|
# * Dongweiming <ciici123@gmail.com>
|
|
#
|
|
# ------------------------------------------------------------------------------
|
|
|
|
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"
|
|
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
|