summaryrefslogtreecommitdiffstats
path: root/Completion/Unix/Command
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Unix/Command')
-rw-r--r--Completion/Unix/Command/_man351
1 files changed, 306 insertions, 45 deletions
diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 67810e1dc..4cba9d625 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -1,16 +1,169 @@
#compdef man apropos whatis
+# Notes:
+# - Solaris is seemingly the only OS that doesn't allow the `man n page` syntax;
+# you must use `man -s n page`
+# - We assume that Linux distributions are using either man-db or mandoc
+# - @todo Option exclusivity isn't super accurate
+# - @todo Solaris man accepts a single hyphen as the first option to disable
+# paging (like AIX's -c); we don't support that
+# - @todo Linux apropos/whatis take options; we don't complete them yet
+
_man() {
- local dirs expl mrd awk
+ local dirs expl mrd awk variant noinsert
+ local -a context line state state_descr args modes
+ local -aU sects
+ local -A opt_args val_args sect_descs
- if (( $words[(I)-M] == (( $CURRENT - 1 )) )); then
- _directories && return 0
- fi
+ if [[ $service == man ]]; then
+ # We'll treat all mandoc-based systems (Alpine, various Illumos distros,
+ # etc.) as OpenBSD
+ _pick_variant -r variant openbsd='-S subsection' $OSTYPE ---
+
+ modes=(
+ -f -K -k -l -R -w -W
+ --apropos
+ --global-apropos
+ --local-file
+ --location
+ --location-cat
+ --recode
+ --whatis
+ --where
+ --where-cat
+ )
+ [[ $variant == darwin* ]] && modes+=( -t )
+
+ args=(
+ "(${(j< >)modes})"{-f,--whatis}'[display short description (like whatis)]'
+ "(${(j< >)modes})"{-k,--apropos}'[search for keyword (like apropos)]'
+ '(-M --manpath)'{-M+,--manpath=}'[specify manual search path]:manual search path:_sequence -s\: _directories'
+ )
+ if [[ $variant == (darwin|dragonfly|freebsd|linux)* ]]; then
+ args+=(
+ '(-a -S -s --all --sections)'{-a,--all}'[display all matching pages]'
+ '(-P --pager)'{-P+,--pager=}'[specify output pager]:pager:_path_commands'
+ # @todo Could enumerate these
+ '(-p --preprocessor)'{-p+,--preprocessor=}'[specify roff preprocessor sequence]:preprocessor sequence'
+ )
+ else
+ args+=( '(-s)-a[display all matching pages]' )
+ fi
+ [[ $variant == (aix|solaris)* ]] || args+=(
+ '(-C --config-file)'{-C+,--config-file=}'[specify configuration file]:configuration file:_files'
+ "(${(j< >)modes})"{-w,--path,--where}'[display file locations]'
+ )
+ [[ $variant == (aix|netbsd|openbsd)* ]] || args+=(
+ # @todo FreeBSD allows this to be given multiple times
+ '(-d --debug)'{-d,--debug}'[display debugging information]'
+ )
+ [[ $variant == (darwin|dragonfly|freebsd|linux|solaris|aix)* ]] && args+=(
+ '(-7 -H -t --ascii --html --troff)'{-t,--troff}'[format man page using troff]'
+ )
+ [[ $variant == (darwin|linux)* ]] && args+=(
+ "(${(j< >)modes})"{-K,--global-apropos}'[search for keyword in all pages]'
+ '(-m --systems)'{-m+,--systems=}'[search manual of specified system]:operating system'
+ )
+ [[ $variant == (darwin|dragonfly|freebsd)* ]] && args+=(
+ '(: -)-h[display help information]'
+ '(-a)-S+[specify manual sections to search]: :->sects'
+ )
+ [[ $variant == (dragonfly|freebsd)* ]] && args+=(
+ # @todo Could enumerate these
+ '-m[search manual of specified architecture]:architecture'
+ '-o[use non-localized man pages]'
+ )
+ [[ $variant == (netbsd|openbsd)* ]] && args+=(
+ '-c[disable paging]'
+ '-m[augment manual search path]:manual search path:_sequence -s\: _directories'
+ '(-a)-s+[specify manual section to search]: :->sects'
+ )
+ [[ $variant == linux* ]] && args+=(
+ '(: -)'{-\?,--help}'[display help information]'
+ '(-7 -t -H -T -Z --ascii --html --troff --troff-device --ditroff)'{-7,--asci}'[translate man pages for 7-bit terminal]'
+ '(-D --default)'{-D,--default}'[reset man to default options]'
+ # @todo Could enumerate these
+ '(-E --encoding)'{-E+,--encoding=}'[specify output encoding]:encoding'
+ '(-e --extension)'{-e+,--extension=}'[specify sub-extension]:sub-extension'
+ '(-H --html)'{-H-,--html=-}'[produce HTML output for specified browser]::Web browser:_path_commands'
+ '(-i -I --ignore-case --match-case)'{-i,--ignore-case}'[search case-insensitively]'
+ '(-i -I --ignore-case --match-case)'{-I,--match-case}'[search case-sensitively]'
+ '(-L --locale)'{-L+,--locale=}'[specify locale]:locale:_locales'
+ "(${(j< >)modes})"{-l+,--local-file=}'[format and display specified file]:*:::manual file:_files'
+ "!(${(j< >)modes})"{--location,--location-cat}
+ '--names-only[match only page names (with --regex or --wildcard)]'
+ '(--nh --no-hyphenation)'{--nh,--no-hyphenation}'[disable hyphenation]'
+ '(--nj --no-justification)'{--nj,--no-justification}'[disable justification]'
+ '--no-subpages[do not combine pairs of page names into single page name]'
+ # @todo Could enumerate these
+ "(${(j< >)modes})"{-R+,--recode=}'[output man page in specified encoding]:encoding'
+ '(-r --prompt)'{-r+,--prompt=}'[specify prompt for less]:less prompt'
+ '(-a --all --wildcard)--regex[treat page name as regular expression]'
+ '(-a -S -s --all --sections)'{-S+,-s+,--sections=}'[specify manual sections to search]: :->sects'
+ # @todo Could enumerate these
+ '(-T -t --troff --troff-device)'{-T-,--troff-device=-}'[specify roff output device]::roff output device'
+ '(-u --update)'{-u,--update}'[update database caches]'
+ '(: -)--usage[display brief usage information]'
+ '(: -)'{-V,--version}'[display version information]'
+ "(${(j< >)modes})"{-W,--where-cat}'[display cat file locations]'
+ '--warnings=[enable specified groff warnings]:groff warnings'
+ '(-a --all --regex)--wildcard[treat page name as shell glob]'