Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: man completion
- X-seq: zsh-workers 50278
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Karel Balej <karelb@xxxxxxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: man completion
- Date: Sun, 22 May 2022 14:26:18 -0700
- Archived-at: <https://zsh.org/workers/50278>
- In-reply-to: <20220522160004.jshcrwlfu2jcyror@asfaloth>
- List-id: <zsh-workers.zsh.org>
- References: <20220515152021.pumg2z3fmfga76vp@asfaloth> <CAH+w=7YMj_TnQ5711ZNDZSqPeYyV+4OuwgmtHFmj8qsroDT9BA@mail.gmail.com> <CAH+w=7Yt84uC0PVNvjoXjh3apmYMgvXNYeSUdqPcg9vaZ4DEKA@mail.gmail.com> <CAH+w=7Zb5Mc=dLw0EdHbHfi4OZRx=gbBH==6chO5FXj38wCK8w@mail.gmail.com> <20220521125731.fexcrwbv7wabrod7@imladris> <CAH+w=7ZBvabbwWh07151ZgGKH4SNW1NChvLP2gVs6wA2hM4bMg@mail.gmail.com> <20220522160004.jshcrwlfu2jcyror@asfaloth>
On Sun, May 22, 2022 at 8:59 AM Karel Balej <karelb@xxxxxxxxxxxxxxxxxxxx> 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.
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author