You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
906 B
31 lines
906 B
# ------------------------------------------------------------------------------ |
|
# 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 "\e\e" sudo-command-line
|
|
|