about summary refs log tree commit diff
path: root/Completion/Unix/Command/_man
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-07-11 08:22:02 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-07-11 08:22:02 +0000
commit027604400ba98f4c947784fc691dc7c93b9bf366 (patch)
tree96072e9c3b307111e1aaf8ca92c2c75570aa78f3 /Completion/Unix/Command/_man
parent1f62b5acbe4a6e5c2c1f704ab1dcfd207afe9919 (diff)
downloadzsh-027604400ba98f4c947784fc691dc7c93b9bf366.tar.gz
zsh-027604400ba98f4c947784fc691dc7c93b9bf366.tar.xz
zsh-027604400ba98f4c947784fc691dc7c93b9bf366.zip
15352,15357
Diffstat (limited to 'Completion/Unix/Command/_man')
-rw-r--r--Completion/Unix/Command/_man61
1 files changed, 61 insertions, 0 deletions
diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
new file mode 100644
index 000000000..0bdd8db8b
--- /dev/null
+++ b/Completion/Unix/Command/_man
@@ -0,0 +1,61 @@
+#compdef man apropos whatis
+
+_man() {
+  local dirs expl mrd awk
+
+  if [[ $service == man ]] && (( $words[(I)-l] + $words[(I)--local-file] )); then
+    _files || return 0
+  fi
+
+  if (( ! $#manpath )); then
+    local mp
+    mp=($(manpath 2>/dev/null))
+    [[ "$mp" == *:* ]] && mp=( ${(s.:.)mp} )
+    manpath=( $mp )
+  fi
+
+  (( $#manpath )) || manpath=( ${(s.:.)$(manpath 2>/dev/null)} ) ||
+      manpath=( /usr/man(-/) /(opt|usr)/(dt|share|X11R6|local)/(cat|)man(-/) )
+
+  # `sman' is the SGML manual directory for Solaris 7.
+  # 1M is system administrator commands on SVR4
+
+  mrd=(${^manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N))
+
+  if [[ $words[2] = (<->*|1M|l|n) ]]; then
+    dirs=( $^manpath/(sman|man|cat)${words[2]}/ )
+    awk="\$2 == \"$words[2]\" {print \$1}"
+  else
+    dirs=( $^manpath/(sman|man|cat)*/ )
+    awk='{print $1}'
+  fi
+
+  _wanted manuals expl 'manual page' _man_pages
+}
+
+_man_pages() {
+  local matcher pages dummy
+
+  zparseopts -E M+:=matcher
+
+  if (( $#matcher )); then
+    matcher=( ${matcher:#-M} )
+    matcher="$matcher"
+  else
+    matcher=
+  fi
+
+  pages=( $dirs )
+  compfiles -p pages '' '' "$matcher" '' dummy '*'
+  pages=( ${^~pages}(N:t:r) )
+
+  (($#mrd)) && pages[$#pages+1]=($(awk $awk $mrd))
+
+  # Remove any compression suffix, then remove the minimum possible string
+  # beginning with .<->: that handles problem cases like files called
+  # `POSIX.1.5'.
+
+  compadd "$@" - ${pages%.(?|<->*)}
+}
+
+_man "$@"