diff options
author | Axel Beckert <abe@deuxchevaux.org> | 2016-12-04 04:32:03 +0100 |
---|---|---|
committer | Axel Beckert <abe@deuxchevaux.org> | 2016-12-04 04:32:03 +0100 |
commit | 3e439c3863f14c82f70666804c8570a13b3732e6 (patch) | |
tree | 07036c43e0f3f9242bb6dd42cd2a849ec8ea8aca /Completion/Unix/Command/_man | |
parent | 2aedc4b88fd0e87b89583983951b04b96f48efd3 (diff) | |
parent | 7b7e84f0815ed22a0ee348a217776529035dccf3 (diff) | |
download | zsh-3e439c3863f14c82f70666804c8570a13b3732e6.tar.gz zsh-3e439c3863f14c82f70666804c8570a13b3732e6.zip |
Merge tag 'zsh-5.2-test-1' into debian
Diffstat (limited to 'Completion/Unix/Command/_man')
-rw-r--r-- | Completion/Unix/Command/_man | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man index 0534db753..b2aaeaf7e 100644 --- a/Completion/Unix/Command/_man +++ b/Completion/Unix/Command/_man @@ -37,27 +37,39 @@ _man() { mrd=(${^_manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N)) - # $sect is from the command line, the "3p" in "man 3p memcpy" + # $sect is from the command line, the "3p" in "man 3p memcpy". + # It may also be a |-joined (and later in the code "()"-enclosed) list of + # section names. + # TODO: disentangle this to always be an array. # $sect_dirname is from the filesystem, the "3" in "/usr/share/man/man3" # These are used by _man_pages local sect sect_dirname if [[ $OSTYPE = solaris* ]]; then sect=${${words[(R)-s*]#-s}:-$words[$words[(i)-s]+1]} + sect="${sect//,/|}" elif [[ -n ${sect:=$words[$words[(i)-S]+1]} || -n ${sect:=$MANSECT} ]]; then - if [[ $sect != ${sect::="${sect//:/|}"} ]]; then - sect="($sect)" - fi + sect="${sect//:/|}" + sect="${sect//,/|}" elif (( CURRENT > 2 )); then sect=$words[2] fi - if [[ $sect = (<->*|1M|l|n) || $sect = \(*\|*\) ]]; then - dirs=( $^_manpath/(sman|man|cat)${~sect%%[^0-9]#}/ ) + if [[ $sect = (<->*|1M|l|n) || $sect = *\|* ]]; then + () { + local -a sects=( ${(s.|.)sect} ) + if [[ $sect != (l|n) ]]; then + sects=( ${sects%%[^0-9]#} ) + fi + dirs=( $^_manpath/(sman|man|cat)${^sects}*/ ) + } + if [[ $sect == *\|* ]]; then sect="($sect)"; fi awk="\$2 == \"$sect\" {print \$1}" else dirs=( $^_manpath/(sman|man|cat)*/ ) awk='{print $1}' fi + # Solaris 11 and on have a man-index directory that doesn't contain manpages + dirs=( ${dirs:#*/man-index/} ) if [[ $OSTYPE = solaris* && ( $words[CURRENT] = -s* || $words[CURRENT-1] == -s ) ]]; then [[ $words[CURRENT] = -s* ]] && compset -P '-s' sects=( ${(o)${dirs##*(man|cat)}%/} ) @@ -78,6 +90,13 @@ _man() { done (( ret )) || return 0 done + ## To fall back to other sections' manpages when completing filenames, like + ## the 'else' codepath does: + # + # if (( ret )) && [[ $PREFIX$SUFFIX == */* ]]; then + # sect_dirname= + # _wanted manuals expl 'manual page' _man_pages && return + # fi return 1 else @@ -87,7 +106,7 @@ _man() { } _man_pages() { - local matcher pages dummy sopt + local pages sopt # What files corresponding to manual pages can end in. local suf='.((?|<->*)(|.gz|.bz2|.Z|.lzma))' @@ -96,22 +115,17 @@ _man_pages() { # Easy way to test for versions of man that allow file names. # This can't be a normal man page reference. # Try to complete by glob first. - _path_files -g "*$suf" && return - _path_files - return - fi - - zparseopts -E M+:=matcher - - if (( $#matcher )); then - matcher=( ${matcher:#-M} ) - matcher="$matcher" - else - matcher= + if [[ -n $sect_dirname ]]; then + _path_files -g "*.*$sect_dirname*(|.gz|.bz2|.Z|.lzma)" "$expl[@]" + else + _path_files -g "*$suf" "$expl[@]" && return + _path_files "$expl[@]" + fi + return $? fi pages=( ${(M)dirs:#*$sect_dirname/} ) - compfiles -p pages '' '' "$matcher" '' dummy "*${(b)sect}*" + pages=( ${^pages}/"*$sect${sect:+"*"}" ); pages=( ${^~pages}(N:t) ) (($#mrd)) && pages[$#pages+1]=($(awk $awk $mrd)) |