From: dana <dana@dana.is>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Improve _man file-path completion
Date: Fri, 3 Jan 2020 18:12:28 -0600 [thread overview]
Message-ID: <83C0ABA0-99A5-4DAD-98D6-DBB919F61E24@dana.is> (raw)
This has been annoying me for a little while. Since we glob for man pages with
_path_files, it's not possible to navigate through sub-directories when
completing file paths. Just using _files fixes that, but then when you have
separate-sections on you get like:
% man /usr/local/l<TAB>
completing manual page, section 1:
lib/ libexec/ local/
completing manual page, section 2:
lib/ libexec/ local/
completing manual page, section 3:
lib/ libexec/ local/
...
Separating by-path pages into sections is nice, but the only way i can think
of to make it work well with directory navigation is to do the globbing
'manually' first and decide what to insert based on that, and that's a bigger
job. (But let me know if you have any better ideas)
dana
diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 41ae85a1f..d4cbbb9ba 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -376,7 +376,13 @@ _man() {
return
}
- if zstyle -t ":completion:${curcontext}:manuals" separate-sections; then
+ # Don't separate sections when we're completing a file path. Otherwise, the
+ # user may see directories repeated a million times (once for each section)
+ # when navigating through the file system
+ if
+ [[ $PREFIX$SUFFIX != */* ]] &&
+ zstyle -t ":completion:${curcontext}:manuals" separate-sections
+ then
local d ret=1
(( $#sects )) || return 1
@@ -392,15 +398,9 @@ _man() {
done
(( ret )) || return 0
done
- ## To fall back to other sections' manpages when completing filenames, like
- ## the 'else' codepath does:
- #
- # if (( ret )) && [[ $PREFIX$SUFFIX == */* ]]; then
- # sect_dirname=
- # _wanted manuals expl 'manual page' _man_pages && return
- # fi
return 1
+
else
sect_dirname=
_wanted manuals expl 'manual page' _man_pages
@@ -414,14 +414,14 @@ _man_pages() {
local suf='.((?|<->*|ntcl)(|.gz|.bz2|.z|.Z|.lzma))'
if [[ $PREFIX$SUFFIX = */* ]]; then
- # Easy way to test for versions of man that allow file names.
- # This can't be a normal man page reference.
- # Try to complete by glob first.
+ # This can be used to glob for an individual section's pages, which is
+ # useful for separate-sections. But the effect is irritating when navigating
+ # through sub-directories; see above
if [[ -n $sect_dirname ]]; then
- _path_files -g "*.*$sect_dirname*(|.gz|.bz2|.z|.Z|.lzma)" "$expl[@]"
+ _files -g "*.*$sect_dirname*(|.gz|.bz2|.z|.Z|.lzma)" "$expl[@]"
else
- _path_files -g "*$suf" "$expl[@]" && return
- _path_files "$expl[@]"
+ _files -g "*$suf" "$expl[@]" && return
+ _files "$expl[@]"
fi
return $?
fi
next reply other threads:[~2020-01-04 0:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-04 0:12 dana [this message]
2020-01-04 0:39 ` Daniel Shahaf
2020-01-04 1:17 ` dana
2020-01-04 1:46 ` Bart Schaefer
2020-01-04 12:46 ` Daniel Shahaf
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=83C0ABA0-99A5-4DAD-98D6-DBB919F61E24@dana.is \
--to=dana@dana.is \
--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).