无法在 Zsh 的 TAB 补全中对 Man 进行两个单词搜索
问题:有一个制表符补全,它需要两个单词并计算它们与 Man 的最佳匹配,然后返回最佳匹配
示例:以下伪代码应给出我至少知道 Zsh 的反向菜单完成命令。 现在,如果没有 zgrep,我无法在手册中搜索手册。
man zsh:reverse <TAB>
其中“:”是我想要的分隔符。
初始问题:使用Zsh搜索手册时,按TAB键输入一个单词时,TAB补全会运行哪些文件?
Problem: to have a tab completion which takes two words and calculates the best match from them for Man, and then returns the best matches
Example: The following pseudo-code should give me at least Zsh's reverse-menu-complete -command. Right now, I cannot search manuals inside manuals without zgrep.
man zsh:reverse <TAB>
where ":" is the separator which I want.
Initial Problem: Which files does the TAB completion run when I press TAB for one word in searching manuals by Zsh?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将尝试深入了解 zsh 补全系统的工作原理以及解决此问题的不完整方法。
当您在 zsh 中对
man
使用 TAB 补全时运行的文件位于/usr/share/zsh/${ZSH_VERSION}/functions
目录下。 该树因发行版而异,但文件名为_man
,并提供man
、apropos
和whatis
的补全。调用 _man 后,其工作原理如下(粗略描述):
man
的完成和--local-file
指定为第一个标志,则调用标准文件完成(< code>_files)$MANPATH
构造manpath
变量。 这是搜索手册页的地方,man
,如果是,则仅搜索zstyle ':completion:*:manuals' 单独的 那些节使用了 -sections true
,输出中的单独部分(不要在它们之间混合)_man_pages
来提供匹配_man_pages
的手册页列表使用compfiles -ppages '' '' "$matcher" '' dummy '*'
做了一些魔法。pages
是包含所请求部分的联机帮助页的所有目录的变量。 实际的通配模式是由隐式参数$PREFIX
和compfiles
的最后一个参数 - 在本例中*
构造的。 这导致/usr/share/man/man1
被转换为/usr/share/man/man1/foo*
_man_pages
匹配的文件,然后从文件中删除所有后缀,并使用compadd
将它们添加到完成小部件选择列表中。现在,如您所见,该列表手册页的数量直接由
$PREFIX
变量确定。 为了使zsh:foo
仅列出包含单词foo
的zsh*
手册页,需要将其拆分为>:
字符(如果有)。_man_pages
中的以下添加部分解决了该问题(zsh 4.3.4):原始:
已修改(查找 ##mod 注释):
但是,它仍然无法完全正常工作(如果您取消注释
#echo "$p matches $manpage_grep"
行,您可以看到它确实构建了列表) - 我怀疑在内部某个地方,完成系统看到,例如,“zshcompctl”与前缀“不匹配” zsh:foo",并且不显示结果匹配。 我试图在剥离 grep 字符串后保持$PREFIX
不变,但它仍然不起作用。无论如何,这至少应该让您开始。
I will attempt to provide an insight to how zsh completion system works and an incomplete go at this problem.
The file that runs when you use TAB completion for
man
in zsh is located under the/usr/share/zsh/${ZSH_VERSION}/functions
directory. The tree varies across distributions, but the file is named_man
, and provides completion forman
,apropos
andwhatis
.After _man is invoked, it works as following (rough description):
man
and--local-file
was specified as first flag, invoke standard files completion (_files
)manpath
variable from a set of defaults /$MANPATH
. This is where the manpages will be searchedman
with a section number parameter, if yes - only those sections will be searchedzstyle ':completion:*:manuals' separate-sections true
was used, separate sections in output (don't mix between them)_man_pages
to provide a list of man pages for the match_man_pages
now does a bit of magic withcompfiles -p pages '' '' "$matcher" '' dummy '*'
.pages
is the variable with all the directories containing manpages for requested section(s). The actual globbing pattern is constructed from the implicit parameter$PREFIX
and the last parameter tocompfiles
-*
in this case. This results in/usr/share/man/man1
to be transformed into/usr/share/man/man1/foo*
_man_pages
then strips any suffixes from the files and adds them to the completion widget list of choices by usingcompadd
Now, as you can see, the list of manpages is directly determined by
$PREFIX
variable. In order to makezsh:foo
to list only man pages ofzsh*
which contain the wordfoo
, it needs to be split across:
character (if any).The following addition in
_man_pages
partially solve the issue (zsh 4.3.4):Original:
Modified (look for ##mod comments):
However, it's still not fully working (if you uncomment the
#echo "$p matched $manpage_grep"
line, you can see that it does build the list) - I suspect that somewhere internally, the completion system sees that, for instance, "zshcompctl" is not matched by prefix "zsh:foo", and does not display the resulting matches. I've tried to keep$PREFIX
as it is after stripping the grep string, but it still does not want to work.At any rate, this at least should get you started.