From 55457187d18221e76bd12f0fb2cfab65c49b92fb Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Tue, 5 Mar 2019 01:09:01 +0100
Subject: Initial commit
---
.oh-my-zsh/plugins/sudo/README.md | 57 +++++++++++++++++++++++++++++++++
.oh-my-zsh/plugins/sudo/sudo.plugin.zsh | 31 ++++++++++++++++++
2 files changed, 88 insertions(+)
create mode 100644 .oh-my-zsh/plugins/sudo/README.md
create mode 100644 .oh-my-zsh/plugins/sudo/sudo.plugin.zsh
(limited to '.oh-my-zsh/plugins/sudo')
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 esc 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 esc 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 esc 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
+#
+# ------------------------------------------------------------------------------
+
+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
--
cgit v1.2.3