diff options
author | Marvin Borner | 2019-03-05 01:09:01 +0100 |
---|---|---|
committer | Marvin Borner | 2019-03-05 01:09:01 +0100 |
commit | 55457187d18221e76bd12f0fb2cfab65c49b92fb (patch) | |
tree | 8db042d2d80710d54100c2709ad4332153ac848a /.oh-my-zsh/plugins/sudo |
Initial commit
Diffstat (limited to '.oh-my-zsh/plugins/sudo')
-rw-r--r-- | .oh-my-zsh/plugins/sudo/README.md | 57 | ||||
-rw-r--r-- | .oh-my-zsh/plugins/sudo/sudo.plugin.zsh | 31 |
2 files changed, 88 insertions, 0 deletions
diff --git a/.oh-my-zsh/plugins/sudo/README.md b/.oh-my-zsh/plugins/sudo/README.md new file mode 100644 index 0000000..ebfdfd1 --- /dev/null +++ b/.oh-my-zsh/plugins/sudo/README.md @@ -0,0 +1,57 @@ +# sudo + +Easily prefix your current or previous commands with `sudo` by pressing <kbd>esc</kbd> twice + +## Enabling the plugin + +1. Open your `.zshrc` file and add `sudo` in the plugins section: + + ```zsh + plugins=( + # all your enabled plugins + sudo + ) + ``` + +2. Reload the source file or restart your Terminal session: + + ```console + $ source ~/.zshrc + $ + ``` + +## Usage examples + +### Current typed commands + +Say you have typed a long command and forgot to add `sudo` in front: + +```console +$ apt-get install build-essential +``` + +By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo` prefixed without typing: + +```console +$ sudo apt-get install build-essential +``` + +### Previous executed commands + +Say you want to delete a system file and denied: + +```console +$ rm some-system-file.txt +-su: some-system-file.txt: Permission denied +$ +``` + +By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo` prefixed without typing: + +```console +$ rm some-system-file.txt +-su: some-system-file.txt: Permission denied +$ sudo rm some-system-file.txt +Password: +$ +``` diff --git a/.oh-my-zsh/plugins/sudo/sudo.plugin.zsh b/.oh-my-zsh/plugins/sudo/sudo.plugin.zsh new file mode 100644 index 0000000..0b84382 --- /dev/null +++ b/.oh-my-zsh/plugins/sudo/sudo.plugin.zsh @@ -0,0 +1,31 @@ +# ------------------------------------------------------------------------------ +# 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 |