如何在 Perl 的 Term::Shell 中自定义制表符补全?
我正在使用 Term::Shell 包来实现 CLI 工具。 该软件包提供了一个 API:comp_CMD
。
每当用户按下 TAB 时就会调用此函数。 我的要求是:
shell>; stack
TAB
over under
`shell>stack overTAB
流示例垃圾
但是默认comp_CMD
仅提供一组 TAB 选项,例如
shell> stack
TAB
over under
`shell>stack overTAB
over under
### 问题是这里
,我想要的是流样本垃圾,而不是在下面。
I am using Term::Shell package to implement a CLI tool. This package provides a API: comp_CMD
.
This function is invoked whenever the user presses the TAB.
My requirement here is:
shell> stack
TAB
over under
`shell>stack overTAB
flow sample junk
But the default comp_CMD
provides only one set of TAB options like
shell> stack
TAB
over under
`shell>stack overTAB
over under
### THE PROBLEM IS HERE
Instead of over under here, I want to get flow sample junk.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
comp_*
样式处理程序,只能将完成的内容与最后一个不完整的单词进行匹配。 然而幸运的是,您可以通过重写 catch_comp 函数来获得所需的结果,如下所示; 它允许与整个命令行进行匹配:With the
comp_*
style handlers one can only match one's completions against the last incomplete word. Fortunately, however, you can get the desired result by overriding the catch_comp function like below; it lets one match against whole command line:我想在这里添加一件事..
在覆盖 rl_complete 子例程之后,我们还必须覆盖 comp__ (调用 TAB 的默认子例程)以避免重复打印子命令。
One more thing i want to add here..
After overriding rl_complete subroutine, we also have to override comp__ (Default subroutine called for TAB) to avoid repeated printing of the subcommands.