sudo.plugin.zsh 659 B

12345678910111213141516171819202122232425
  1. # ------------------------------------------------------------------------------
  2. # Description
  3. # -----------
  4. #
  5. # sudo will be inserted before the command
  6. #
  7. # ------------------------------------------------------------------------------
  8. # Authors
  9. # -------
  10. #
  11. # * Dongweiming <ciici123@gmail.com>
  12. #
  13. # ------------------------------------------------------------------------------
  14. sudo-command-line() {
  15. [[ -z $BUFFER ]] && zle up-history
  16. if [[ $BUFFER == sudo\ * ]]; then
  17. LBUFFER="${LBUFFER#sudo }"
  18. else
  19. LBUFFER="sudo $LBUFFER"
  20. fi
  21. }
  22. zle -N sudo-command-line
  23. # Defined shortcut keys: [Esc] [Esc]
  24. bindkey "\e\e" sudo-command-line