2
0

man.plugin.zsh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # ------------------------------------------------------------------------------
  2. # Author
  3. # ------
  4. #
  5. # * Jerry Ling<jerryling315@gmail.com>
  6. #
  7. # ------------------------------------------------------------------------------
  8. # Usage
  9. # -----
  10. #
  11. # man will be inserted before the command
  12. #
  13. # ------------------------------------------------------------------------------
  14. man-command-line() {
  15. # if there is no command typed, use the last command
  16. [[ -z "$BUFFER" ]] && zle up-history
  17. # if typed command begins with man, do nothing
  18. [[ "$BUFFER" = man\ * ]] && return
  19. # get command and possible subcommand
  20. # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
  21. local -a args
  22. args=(${${(Az)BUFFER}[1]} ${${(Az)BUFFER}[2]})
  23. # check if man page exists for command and first argument
  24. if man "${args[1]}-${args[2]}" >/dev/null 2>&1; then
  25. BUFFER="man $args"
  26. else
  27. BUFFER="man ${args[1]}"
  28. fi
  29. }
  30. zle -N man-command-line
  31. # Defined shortcut keys: [Esc]man
  32. bindkey "\e"man man-command-line