sudo.plugin.zsh 906 B

12345678910111213141516171819202122232425262728293031
  1. # ------------------------------------------------------------------------------
  2. # Description
  3. # -----------
  4. #
  5. # sudo or sudoedit 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. elif [[ $BUFFER == $EDITOR\ * ]]; then
  19. LBUFFER="${LBUFFER#$EDITOR }"
  20. LBUFFER="sudoedit $LBUFFER"
  21. elif [[ $BUFFER == sudoedit\ * ]]; then
  22. LBUFFER="${LBUFFER#sudoedit }"
  23. LBUFFER="$EDITOR $LBUFFER"
  24. else
  25. LBUFFER="sudo $LBUFFER"
  26. fi
  27. }
  28. zle -N sudo-command-line
  29. # Defined shortcut keys: [Esc] [Esc]
  30. bindkey "\e\e" sudo-command-line