2015-07-29 20:05:44 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Author
|
|
|
|
# ------
|
|
|
|
#
|
|
|
|
# * Jerry Ling<jerryling315@gmail.com>
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-09-17 02:16:16 +08:00
|
|
|
# Usage
|
2015-07-29 20:05:44 +08:00
|
|
|
# -----
|
|
|
|
#
|
|
|
|
# man will be inserted before the command
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
man-command-line() {
|
2020-03-16 19:47:15 +08:00
|
|
|
# if there is no command typed, use the last command
|
|
|
|
[[ -z "$BUFFER" ]] && zle up-history
|
|
|
|
|
2020-05-22 02:24:43 +08:00
|
|
|
# if typed command begins with man, do nothing
|
|
|
|
[[ "$BUFFER" = man\ * ]] && return
|
|
|
|
|
|
|
|
# get command and possible subcommand
|
2020-03-16 19:47:15 +08:00
|
|
|
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
|
2020-05-22 02:24:43 +08:00
|
|
|
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
|
2015-07-29 20:05:44 +08:00
|
|
|
}
|
2020-05-22 02:24:43 +08:00
|
|
|
|
2015-07-29 20:05:44 +08:00
|
|
|
zle -N man-command-line
|
|
|
|
# Defined shortcut keys: [Esc]man
|
|
|
|
bindkey "\e"man man-command-line
|