]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/sudo/README.md
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / sudo / README.md
1 # sudo
2
3 Easily prefix your current or previous commands with `sudo` by pressing <kbd>esc</kbd> twice.
4
5 To use it, add `sudo` to the plugins array in your zshrc file:
6
7 ```zsh
8 plugins=(... sudo)
9 ```
10
11 ## Usage
12
13 ### Current typed commands
14
15 Say you have typed a long command and forgot to add `sudo` in front:
16
17 ```console
18 $ apt-get install build-essential
19 ```
20
21 By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo` prefixed without typing:
22
23 ```console
24 $ sudo apt-get install build-essential
25 ```
26
27 The same happens for editing files with your default editor (defined in `$SUDO_EDITOR`, `$VISUAL` or `$EDITOR`, in that order):
28
29 If the editor defined were `vim`:
30
31 ```console
32 $ vim /etc/hosts
33 ```
34
35 By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo -e` instead of the editor, that would open that editor with root privileges:
36
37 ```console
38 $ sudo -e /etc/hosts
39 ```
40
41 ### Previous executed commands
42
43 Say you want to delete a system file and denied:
44
45 ```console
46 $ rm some-system-file.txt
47 -su: some-system-file.txt: Permission denied
48 $
49 ```
50
51 By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo` prefixed without typing:
52
53 ```console
54 $ rm some-system-file.txt
55 -su: some-system-file.txt: Permission denied
56 $ sudo rm some-system-file.txt
57 Password:
58 $
59 ```
60
61 The same happens for file editing, as told before.
62
63 ## Key binding
64
65 By default, the `sudo` plugin uses <kbd>Esc</kbd><kbd>Esc</kbd> as the trigger.
66 If you want to change it, you can use the `bindkey` command to bind it to a different key:
67
68 ```sh
69 bindkey -M emacs '<seq>' sudo-command-line
70 bindkey -M vicmd '<seq>' sudo-command-line
71 bindkey -M viins '<seq>' sudo-command-line
72 ```
73
74 where `<seq>` is the sequence you want to use. You can find the keyboard sequence
75 by running `cat` and pressing the keyboard combination you want to use.