From d27c85fbe1bbfb752dd4a93870ef37d315acb830 Mon Sep 17 00:00:00 2001 From: Raf Czlonka Date: Wed, 31 Mar 2021 13:07:11 +0100 Subject: [PATCH] Fix and improve man(1) completion Fixes several issues in the current `man(1)` completion: - _section_ numbers are not stripped off - _Perl Programmers Reference Guide_ (`3p`) section is ignored - manual page name can only be completed as the 1st argument While there, add several more manual page hierarchies, i.e. `cat*` for _graphiz_ on OpenBSD, `/usr/local/share/man` on macOS, etc. --- completions/man.ksh | 8 +++++--- completions/man.org | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/completions/man.ksh b/completions/man.ksh index cd5621f..7907c77 100755 --- a/completions/man.ksh +++ b/completions/man.ksh @@ -2,8 +2,10 @@ MAN_CACHE=$LOAD_PATH/cache/man if [ ! -f $MAN_CACHE ]; then mkdir -p $(dirname ${MAN_CACHE}) - ls /usr/{share,X11R6,local}/man/man[1-9] | sort -u > $MAN_CACHE + for i in /usr{,/X11R6,/local}{,/share}/man/{,cat,man}[1-9lnp]{,f,p} + do + test -d $i && ls $i + done | rev | cut -d. -f2- | rev | sort -u > $MAN_CACHE fi -set -A complete_man_1 -- $(cat $MAN_CACHE) - +set -A complete_man -- $(cat $MAN_CACHE) diff --git a/completions/man.org b/completions/man.org index 947f490..d1a5c40 100644 --- a/completions/man.org +++ b/completions/man.org @@ -5,7 +5,10 @@ Completions for man pages are found via: #+begin_src shell -ls /usr/{share,X11R6,local}/man/man[1-9] | sort -u > $MAN_CACHE +for i in /usr{,/X11R6,/local}{,/share}/man/{,cat,man}[1-9lnp]{,f,p} +do + test -d $i && ls $i +done | rev | cut -d. -f2- | rev | sort -u > $MAN_CACHE #+end_src Currently the cache is never re-created. Operating without a cache causes