25d0b2dfbd4f4c915a9c04e29a97b82ebd4e612c

Author
wurza <Wurzy96@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

man: look for man page for subcommands (#8798)

Diff

 1diff --git a/plugins/man/man.plugin.zsh b/plugins/man/man.plugin.zsh
 2index 3ab15d32392839de92363b4f54412a59b0186fbb..dcba613ae81f23992adb75b932bfac6f369df405 100644
 3--- a/plugins/man/man.plugin.zsh
 4+++ b/plugins/man/man.plugin.zsh
 5@@ -16,16 +16,22 @@ man-command-line() {
 6     # if there is no command typed, use the last command
 7     [[ -z "$BUFFER" ]] && zle up-history
 8 
 9-    # prepend man to only the first part of the typed command
10+    # if typed command begins with man, do nothing
11+    [[ "$BUFFER" = man\ * ]] && return
12+
13+    # get command and possible subcommand
14     # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
15-    [[ "$BUFFER" != man\ * ]] && BUFFER="man ${${(Az)BUFFER}[1]}"
16+    local -a args
17+    args=(${${(Az)BUFFER}[1]} ${${(Az)BUFFER}[2]})
18+
19+    # check if man page exists for command and first argument
20+    if man "${args[1]}-${args[2]}" >/dev/null 2>&1; then
21+        BUFFER="man $args"
22+    else
23+        BUFFER="man ${args[1]}"
24+    fi
25 }
26+
27 zle -N man-command-line
28 # Defined shortcut keys: [Esc]man
29 bindkey "\e"man man-command-line
30-
31-
32-# ------------------------------------------------------------------------------
33-# Also, you might want to use man-preview included in 'osx' plugin
34-# just substitute "man" in the function with "man-preview" after you included OS X in
35-# the .zshrc