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

Re: [PATCH] Improve _man file-path completion



On 3 Jan 2020, at 18:39, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> How about this (relative to master)?  It fixes your original problem but
> retains the separate-sections behaviour for man pages specified by filename.

Oh, that's much smarter, thank you.

I do see some minor issues with it:

* It creates a confusing inconsistency where it will automatically complete
  directories in the CWD, but not files (because files still need a / in the
  argument)

* It offers directories first, which i think will be annoying in the more
  common case of trying to complete a man page from the database/MANPATH

* It offers to complete paths unconditionally, which isn't actually supported
  by some man implementations/modes (OpenBSD requires -l for example). We were
  just assuming that the user knew what they were doing if they had a / in the
  argument, which i think is probably still sufficient

* Plural description

How about something like the following, then?

On 3 Jan 2020, at 18:39, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> Aside:
>
>    % compdef _f f
>    % _f() _files -/
>    % f Util/<TAB>
> .
> offers files, rather than nothing.  Bug?

I seem to recall this being discussed before, and it isn't really a bug, but
we could change it if we decided to. Someone was complaining about it on IRC
just the other day. I think we'd simply need to remove *:all-files from
pats=(...)

dana


diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 41ae85a1f..7d55201e3 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -381,7 +381,12 @@ _man() {
 
     (( $#sects )) || return 1
 
-    _tags manuals.${^sects}
+    if [[ $PREFIX$SUFFIX == */* ]]; then
+      _tags manuals.${^sects} files
+    else
+      _tags manuals.${^sects}
+    fi
+
     while _tags; do
       for sect_dirname in $sects; do
         d=$sect_dirname
@@ -390,6 +395,8 @@ _man() {
         _requested manuals.$sect_dirname expl "manual page, section $d" _man_pages &&
             ret=0
       done
+      [[ $PREFIX$SUFFIX == */* ]] &&
+      _requested files expl directory _files -/ && ret=0
       (( ret )) || return 0
     done
     ## To fall back to other sections' manpages when completing filenames, like



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