Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Improve _man file-path completion
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author