mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-09-21 10:27:09 +00:00
Merge pull request #418 from vicmunoz/sudo_plugin
- plugins: Add plugin "sudo" - plugins/sudo: Add keybindings following OMZ
This commit is contained in:
commit
b15ef2ddb8
50
plugins/sudo/README.md
Normal file
50
plugins/sudo/README.md
Normal file
@ -0,0 +1,50 @@
|
||||
# sudo
|
||||
|
||||
Easily prefix your current or previous commands with `sudo` by pressing <kbd>esc</kbd> twice.
|
||||
|
||||
To use it, add `sudo` to the plugins array in your bashrc file:
|
||||
|
||||
```bash
|
||||
plugins=(... sudo)
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### 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:
|
||||
$
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
||||
Inspired by ohmyzsh sudo plugin.
|
||||
|
13
plugins/sudo/sudo.plugin.sh
Normal file
13
plugins/sudo/sudo.plugin.sh
Normal file
@ -0,0 +1,13 @@
|
||||
#! bash oh-my-bash.module
|
||||
|
||||
function _omb_plugin_sudo_add_sudo {
|
||||
if [[ -z $READLINE_LINE ]]; then
|
||||
READLINE_LINE="$(fc -ln -1 | command sed 's/^[[:space:]]\{1,\}//')"
|
||||
fi
|
||||
READLINE_LINE="sudo $READLINE_LINE"
|
||||
((READLINE_POINT += 5))
|
||||
}
|
||||
|
||||
bind -m emacs -x '"\e\e": _omb_plugin_sudo_add_sudo'
|
||||
bind -m vi-insert -x '"\e\e": _omb_plugin_sudo_add_sudo'
|
||||
bind -m vi-command -x '"\e\e": _omb_plugin_sudo_add_sudo'
|
Loading…
Reference in New Issue
Block a user