diff options
Diffstat (limited to 'plugins/man/man.plugin.zsh')
-rw-r--r-- | plugins/man/man.plugin.zsh | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/plugins/man/man.plugin.zsh b/plugins/man/man.plugin.zsh index 94aa4918d..dcba613ae 100644 --- a/plugins/man/man.plugin.zsh +++ b/plugins/man/man.plugin.zsh @@ -13,15 +13,25 @@ # ------------------------------------------------------------------------------ man-command-line() { - [[ -z $BUFFER ]] && zle up-history - [[ $BUFFER != man\ * ]] && LBUFFER="man $LBUFFER" + # if there is no command typed, use the last command + [[ -z "$BUFFER" ]] && zle up-history + + # if typed command begins with man, do nothing + [[ "$BUFFER" = man\ * ]] && return + + # get command and possible subcommand + # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags + local -a args + args=(${${(Az)BUFFER}[1]} ${${(Az)BUFFER}[2]}) + + # check if man page exists for command and first argument + if man "${args[1]}-${args[2]}" >/dev/null 2>&1; then + BUFFER="man $args" + else + BUFFER="man ${args[1]}" + fi } + zle -N man-command-line # Defined shortcut keys: [Esc]man bindkey "\e"man man-command-line - - -# ------------------------------------------------------------------------------ -# Also, you might want to use man-preview included in 'osx' plugin -# just substitute "man" in the function with "man-preview" after you included OS X in -# the .zshrc |