Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] _path_commands' extra-verbose mode does not work on macOS



On 19 Mar, Marlon Richert wrote:
> The reason for this is that macOS's `whatis` does not support the
> `--version` and `-r` flags:

I can't help you for macOS so you'll have to experiment with whatis and
apropos or perhaps find a way to get at the windex files. The following
patch may make it easier.

The implementation is fairly old and was perhaps always Linux and/or
groff specific. I can't find any modern implementation where output from
whatis --version matches 'whatis from'. The following works for the
main BSDs along with Linux using either man-db (e.g. Redhat) or mandoc
(e.g. Void). I couldn't find a way to list the man index on Solaris 11
(on older Solaris it could use the windex files directly but they've
changed to a proper database for indexing).

mandoc's more advanced searching only works for man pages using the mdoc
macro set so aren't much help.

Oliver

diff --git a/Completion/Unix/Type/_path_commands b/Completion/Unix/Type/_path_commands
index 4d5a6c5af..59b146a88 100644
--- a/Completion/Unix/Type/_path_commands
+++ b/Completion/Unix/Type/_path_commands
@@ -24,13 +24,33 @@ return 1
 }
 
 _call_whatis() { 
-  case "$(whatis --version)" in
-  ("whatis from "*)
-    local -A args
-    zparseopts -D -A args s: r:
-    apropos "${args[-r]:-"$@"}" | fgrep "($args[-s]"
+  local sec impl variant sections=( 1 6 8 )
+  case "$OSTYPE" in
+    (#i)dragonfly|(free|open)bsd*) impl=mandoc ;;
+    netbsd*) impl=apropos ;;
+    linux-gnu*)
+      sections=( 1 8 )
+      # The same test as for man so has a good chance of being cached
+      _pick_variant -c man -r variant \
+        freebsd='-S mansect' \
+        openbsd='-S subsection' \
+        $OSTYPE \
+        ---
+      [[ $variant = $OSTYPE ]] && impl=man-db || impl=mandoc
+    ;;
+  esac
+  case $impl in
+    mandoc)
+      for sec in $sections; do
+        whatis -s $sec .\*
+      done
+    ;;
+    man-db)
+      whatis -s ${(j.,.)sections} -r .\*
+    ;;
+    apropos)
+      apropos -l ''|grep "([${(j..)sections}])"
     ;;
-  (*) whatis "$@";;
   esac
 }
 
@@ -49,7 +69,7 @@ if zstyle -t ":completion:${curcontext}:" extra-verbose; then
   if ( [[ -n $first ]] || _cache_invalid command-descriptions ) && \
     ! _retrieve_cache command-descriptions; then
     local line
-    for line in "${(f)$(_call_program command-descriptions _call_whatis -s 1 -r .\\\*\; _call_whatis -s 6 -r .\\\* 2>/dev/null)}"; do
+    for line in "${(f)$(_call_program command-descriptions _call_whatis)}"; do
       [[ -n ${line:#(#b)([^ ]#) #\([^ ]#\)( #\[[^ ]#\]|)[ -]#(*)} ]] && continue;
       [[ -z $match[1] || -z $match[3] || -z ${${match[1]}:#*:*} ]] && continue;
       _command_descriptions[$match[1]]=$match[3]




Messages sorted by: Reverse Date, Date, Thread, Author