summaryrefslogtreecommitdiffstats
path: root/zsh/oh-my-zsh/plugins/man
diff options
context:
space:
mode:
Diffstat (limited to 'zsh/oh-my-zsh/plugins/man')
-rw-r--r--zsh/oh-my-zsh/plugins/man/README.md13
-rw-r--r--zsh/oh-my-zsh/plugins/man/man.plugin.zsh37
2 files changed, 50 insertions, 0 deletions
diff --git a/zsh/oh-my-zsh/plugins/man/README.md b/zsh/oh-my-zsh/plugins/man/README.md
new file mode 100644
index 0000000..4601252
--- /dev/null
+++ b/zsh/oh-my-zsh/plugins/man/README.md
@@ -0,0 +1,13 @@
+# Man plugin
+
+This plugin adds a shortcut to insert man before the previous command.
+
+To use it, add `man` to the plugins array in your zshrc file:
+
+```zsh
+plugins=(... man)
+```
+# Keyboard Shortcuts
+| Shortcut | Description |
+|-----------------------------------|------------------------------------------------------------------------|
+| <kbd>Esc</kbd> + man | add man before the previous command to see the manual for this command |
diff --git a/zsh/oh-my-zsh/plugins/man/man.plugin.zsh b/zsh/oh-my-zsh/plugins/man/man.plugin.zsh
new file mode 100644
index 0000000..dcba613
--- /dev/null
+++ b/zsh/oh-my-zsh/plugins/man/man.plugin.zsh
@@ -0,0 +1,37 @@
+# ------------------------------------------------------------------------------
+# Author
+# ------
+#
+# * Jerry Ling<jerryling315@gmail.com>
+#
+# ------------------------------------------------------------------------------
+# Usage
+# -----
+#
+# man will be inserted before the command
+#
+# ------------------------------------------------------------------------------
+
+man-command-line() {
+ # 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