my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

3 years ago
  1. # sudo
  2. Easily prefix your current or previous commands with `sudo` by pressing <kbd>esc</kbd> twice.
  3. To use it, add `sudo` to the plugins array in your zshrc file:
  4. ```zsh
  5. plugins=(... sudo)
  6. ```
  7. ## Usage
  8. ### Current typed commands
  9. Say you have typed a long command and forgot to add `sudo` in front:
  10. ```console
  11. $ apt-get install build-essential
  12. ```
  13. By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo` prefixed without typing:
  14. ```console
  15. $ sudo apt-get install build-essential
  16. ```
  17. The same happens for editing files with your default editor (defined in `$SUDO_EDITOR`, `$VISUAL` or `$EDITOR`, in that order):
  18. If the editor defined were `vim`:
  19. ```console
  20. $ vim /etc/hosts
  21. ```
  22. 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:
  23. ```console
  24. $ sudo -e /etc/hosts
  25. ```
  26. ### Previous executed commands
  27. Say you want to delete a system file and denied:
  28. ```console
  29. $ rm some-system-file.txt
  30. -su: some-system-file.txt: Permission denied
  31. $
  32. ```
  33. By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo` prefixed without typing:
  34. ```console
  35. $ rm some-system-file.txt
  36. -su: some-system-file.txt: Permission denied
  37. $ sudo rm some-system-file.txt
  38. Password:
  39. $
  40. ```
  41. The same happens for file editing, as told before.
  42. ## Key binding
  43. By default, the `sudo` plugin uses <kbd>Esc</kbd><kbd>Esc</kbd> as the trigger.
  44. If you want to change it, you can use the `bindkey` command to bind it to a different key:
  45. ```sh
  46. bindkey -M emacs '<seq>' sudo-command-line
  47. bindkey -M vicmd '<seq>' sudo-command-line
  48. bindkey -M viins '<seq>' sudo-command-line
  49. ```
  50. where `<seq>` is the sequence you want to use. You can find the keyboard sequence
  51. by running `cat` and pressing the keyboard combination you want to use.