From: Bart Schaefer <schaefer@brasslantern.com>
To: Karel Balej <karelb@gimli.ms.mff.cuni.cz>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: man completion
Date: Sun, 22 May 2022 14:26:18 -0700 [thread overview]
Message-ID: <CAH+w=7Y4HHQpw9wS0VN9-ow66J3xtNpzgdWrHgLHWOmbmVnugQ@mail.gmail.com> (raw)
In-Reply-To: <20220522160004.jshcrwlfu2jcyror@asfaloth>
[-- Attachment #1: Type: text/plain, Size: 508 bytes --]
On Sun, May 22, 2022 at 8:59 AM Karel Balej <karelb@gimli.ms.mff.cuni.cz> wrote:
>
> It seems that `man -w` does this for both man-db and mandoc (no mention
> about it in the AIX man manual page for instance, though)
The existing completion function implies that -w / --path / --where
all work on aix and solaris. There's no clear indication whether it
can be called with no arguments to display all possible paths ... but
let's try the following and see if anyone complains. Includes the
previous patch.
[-- Attachment #2: _man.txt --]
[-- Type: text/plain, Size: 2151 bytes --]
diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index dba1d13dc..190811e41 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -16,7 +16,7 @@
_man() {
local dirs expl mrd awk variant noinsert
local -a context line state state_descr args modes
- local -aU sects
+ local -aU sects _manpath
local -A opt_args val_args sect_descs
if [[ $service == man ]]; then
@@ -168,29 +168,40 @@ _man() {
_arguments -s -S : $args '*::: :->man' && return 0
[[ -n $state ]] || return 1
+ # Override man path
+ [[ -n ${opt_args[-M]} ]] &&
+ _manpath=( ${(s<:>)opt_args[-M]} )
+
+ # Restore cached man path to avoid $(manpath) if we can
if (( ! $#_manpath )); then
- local mp
- mp=( ${(s.:.)$(manpath 2>/dev/null)} )
- [[ "$mp" == *:* ]] && mp=( ${(s.:.)mp} )
- if (( $#mp )); then
- _manpath=( $mp )
- elif (( $#manpath )); then
- _manpath=( $manpath )
+ if (( ! $+_manpath_cache )); then
+ typeset -gHA _manpath_cache
fi
+ if [[ -z $_manpath_cache[$MANPATH] ]]; then
+ local mp
+ mp=( ${(s.:.)$({ command man -w || manpath } 2>/dev/null)} )
+ [[ "$mp" == *:* ]] && mp=( ${(s.:.)mp} )
+ if (( $#mp )); then
+ _manpath_cache[$MANPATH]=${(j.:.)mp}
+ elif (( $#manpath )); then
+ _manpath_cache[$MANPATH]=$MANPATH
+ fi
+ fi
+ _manpath=( ${(s.:.)_manpath_cache[$MANPATH]} )
+ fi
+
+ # Augment man path
+ if [[ -n ${opt_args[-m]} ]]; then
+ [[ $variant == (netbsd|openbsd)* ]] &&
+ _manpath+=( ${(s<:>)opt_args[-m]} )
+ elif [[ $variant == aix* ]]; then
+ # _manpath declared -U so no need to test
+ _manpath+=( /usr/share/man )
fi
(( $#_manpath )) ||
_manpath=( /usr/man(-/) /(opt|usr)/(pkg|dt|share|X11R6|local)/(cat|)man(-/) )
- # Override man path
- [[ -n ${opt_args[-M]} ]] &&
- _manpath=( ${(s<:>)opt_args[-M]} )
-
- # Augment man path
- [[ $variant == (netbsd|openbsd)* ]] &&
- [[ -n ${opt_args[-m]} ]] &&
- _manpath+=( ${(s<:>)opt_args[-m]} )
-
# `sman' is the SGML manual directory for Solaris 7.
# 1M is system administrator commands on SVR4
next prev parent reply other threads:[~2022-05-22 21:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-15 15:20 Karel Balej
2022-05-15 16:45 ` Bart Schaefer
2022-05-16 19:41 ` Bart Schaefer
2022-05-16 21:40 ` Mikael Magnusson
2022-05-17 0:41 ` Bart Schaefer
2022-05-21 12:57 ` Karel Balej
2022-05-21 20:22 ` Bart Schaefer
2022-05-22 16:00 ` Karel Balej
2022-05-22 21:26 ` Bart Schaefer [this message]
2022-05-23 12:28 ` Karel Balej
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='CAH+w=7Y4HHQpw9wS0VN9-ow66J3xtNpzgdWrHgLHWOmbmVnugQ@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=karelb@gimli.ms.mff.cuni.cz \
--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).