diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2020-05-29 11:01:03 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2020-05-29 11:01:03 -0600 |
commit | a3be2e4084285d7625e63bfe4b951c58143e3c9c (patch) | |
tree | a018be4daef44a51b91477f38da514867659c7d6 /plugins/man/man.plugin.zsh | |
parent | 191e14cc7f63c4525a0f66d571416faf9e91a185 (diff) | |
parent | 93cc3964e2d265ab0571298d69d2eed0a65d13f2 (diff) | |
download | zsh-a3be2e4084285d7625e63bfe4b951c58143e3c9c.tar.gz zsh-a3be2e4084285d7625e63bfe4b951c58143e3c9c.tar.bz2 zsh-a3be2e4084285d7625e63bfe4b951c58143e3c9c.zip |
Merge branch 'master' of https://github.com/ohmyzsh/ohmyzsh
Diffstat (limited to 'plugins/man/man.plugin.zsh')
-rw-r--r-- | plugins/man/man.plugin.zsh | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/plugins/man/man.plugin.zsh b/plugins/man/man.plugin.zsh index 3ab15d323..dcba613ae 100644 --- a/plugins/man/man.plugin.zsh +++ b/plugins/man/man.plugin.zsh @@ -16,16 +16,22 @@ man-command-line() { # if there is no command typed, use the last command [[ -z "$BUFFER" ]] && zle up-history - # prepend man to only the first part of the typed command + # 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 - [[ "$BUFFER" != man\ * ]] && BUFFER="man ${${(Az)BUFFER}[1]}" + 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 |