From: dana <dana@dana.is>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: Zsh workers <zsh-workers@zsh.org>
Subject: Re: [PATCH] Completion: Improve _man (3)
Date: Fri, 15 Jun 2018 08:59:03 -0500 [thread overview]
Message-ID: <53F42356-22E5-453F-9A61-25E71AFAC3BF@dana.is> (raw)
In-Reply-To: <C1FBF43A-6170-4675-ADFA-1C9540B17E26@dana.is>
Round 3, i suppose:
* Re-add the partial section-name matching functionality that Daniel mentioned
* More accurately determine whether an initial operand could be a section name
* Support .z compression extension (per man-db)
* Add some more documentation
Daniel (or anyone), if you have time, could you see if this works as you'd
expect?
dana
diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 11c2fab7f..10395de0e 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -4,6 +4,11 @@
# - 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 Would be nice to support completing the initial operand as a section
+# name (on non-Solaris systems)
+# - @todo We don't support the man-db syntax <name>.<section> (e.g., `ls.1`)
+# - @todo We don't support the man-db feature of 'sub-pages' — that is, treating
+# pairs of operands like `git diff` as `git-diff`
# - @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
@@ -220,7 +225,15 @@ _man() {
elif [[ $variant == (dragonfly|freebsd)* ]] && (( $+opt_args[-S] )); then
noinsert=1
sect=${opt_args[-S]//:/|}
- elif (( CURRENT > 1 )) && [[ $variant != solaris* ]]; then
+ # It's only a small help, but, per man-db, we can avoid treating an initial
+ # operand like `8139too` as a section name by ensuring that only the first
+ # character is a digit. This doesn't do much for stuff like `2to3`, but we can
+ # at least special-case a few common patterns for now
+ elif
+ (( CURRENT > 1 )) &&
+ [[ $variant != solaris* ]] &&
+ [[ ${${(Q)words[1]}##(2to3|7z)*} == ([0-9](|[^0-9[:punct:]]*)|[lnopx]) ]]
+ then
noinsert=1
sect=$words[1]
elif [[ -n ${sect:=$MANSECT} ]]; then
@@ -231,8 +244,24 @@ _man() {
sect=${(Q)sect}
if [[ $sect = (<->*|[lnopx]) || $sect = *\|* ]]; then
- sects=( ${(s.|.)sect} )
- dirs=( $^_manpath/(sman|man|cat)${^sects}(|.*)/ )
+ # Most man implementations support partial matching of a page's
+ # (sub-)section name — e.g., `3per` for `3perl`. The (sub-)section name may
+ # or may not correspond to the directory name (most systems combine
+ # sub-sections), but we'll assume that if it starts with a number and we're
+ # not on Solaris (which doesn't support this feature at all) that we can do
+ # a match against the leading number. This is irritating if you DO want the
+ # exact sub-section specified, but unfortunately there's no way to determine
+ # this programmatically — i guess we could add a style to control it
+ () for 1 {
+ if [[ $OSTYPE == solaris* || $1 != <->* ]]; then
+ sects+=( $1 )
+ dirs+=( $^_manpath/(sman|man|cat)$1(|.*)/ )
+ else
+ sects+=( ${1%%[^0-9]#} )
+ dirs+=( $^_manpath/(sman|man|cat)${1%%[^0-9]#}*/ )
+ fi
+ } ${(s.|.)sect}
+
sect=${(j<|>)sects}
[[ $sect == *'|'* ]] && sect="($sect)"
awk="\$2 == \"$sect\" {print \$1}"
@@ -281,7 +310,7 @@ _man() {
8 'maintenance commands and procedures'
9 'kernel features'
9lua 'Lua kernel bindings' # NetBSD
- l 'local documentation' # AIX, etc.
+ l 'local documentation' # AIX, etc. — TCL on some systems?
n 'new documentation' # AIX, etc.
o 'old documentation' # AIX, etc.
p 'public documentation' # AIX, etc.
@@ -380,14 +409,14 @@ _man_pages() {
local pages sopt
# What files corresponding to manual pages can end in.
- local suf='.((?|<->*|ntcl)(|.gz|.bz2|.Z|.lzma))'
+ local suf='.((?|<->*|ntcl)(|.gz|.bz2|.z|.Z|.lzma))'
if [[ $PREFIX$SUFFIX = */* ]]; then
# 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.
if [[ -n $sect_dirname ]]; then
- _path_files -g "*.*$sect_dirname*(|.gz|.bz2|.Z|.lzma)" "$expl[@]"
+ _path_files -g "*.*$sect_dirname*(|.gz|.bz2|.z|.Z|.lzma)" "$expl[@]"
else
_path_files -g "*$suf" "$expl[@]" && return
_path_files "$expl[@]"
next prev parent reply other threads:[~2018-06-15 13:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-10 6:06 [PATCH] Completion: Improve _man dana
2018-06-10 13:07 ` Oliver Kiddle
2018-06-10 14:02 ` dana
2018-06-11 10:48 ` [PATCH] Completion: Improve _man (2) dana
2018-06-14 9:50 ` Daniel Shahaf
2018-06-14 10:20 ` dana
2018-06-15 13:59 ` dana [this message]
2018-06-15 14:05 ` [PATCH] Completion: Improve _man (3) Daniel Shahaf
2018-06-15 14:21 ` dana
2018-06-15 14:39 ` Mikael Magnusson
2018-06-15 14:55 ` Daniel Shahaf
2018-06-15 15:14 ` dana
2018-06-15 15:36 ` Peter Stephenson
2018-06-15 17:27 ` Mikael Magnusson
2018-06-15 14:47 ` Daniel Shahaf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53F42356-22E5-453F-9A61-25E71AFAC3BF@dana.is \
--to=dana@dana.is \
--cc=d.s@daniel.shahaf.name \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).