diff options
Diffstat (limited to 'config/zsh/plugins/sudo.zsh')
| -rw-r--r-- | config/zsh/plugins/sudo.zsh | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/config/zsh/plugins/sudo.zsh b/config/zsh/plugins/sudo.zsh new file mode 100644 index 0000000..fd43b93 --- /dev/null +++ b/config/zsh/plugins/sudo.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# sudo or sudoedit will be inserted before the command +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Dongweiming <ciici123@gmail.com> +# +# ------------------------------------------------------------------------------ + +MAGIC_ENTER_GIT_COMMAND='git status'; +MAGIC_ENTER_OTHER_COMMAND='ls'; + +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; +bindkey '^Z' sudo-command-line; + |
