简体   繁体   English

如何将子命令传递回bash完成?

[英]How to pass subcommand back into bash completion?

I've written a command which could be compared to time or timeout in that it's used at the start of the line as a prefix to any other bash command. 我编写了一个可以与timetimeout进行比较的命令,因为该命令在行的开头用作任何其他bash命令的前缀。 My question is, how do I convince my bash completion script/rule to run the normal completion for the subcommand - exactly as it would do if my prefix command wasn't present? 我的问题是,如何说服我的bash完成脚本/规则为子命令运行正常的完成-完全与不存在我的前缀命令的情况一样?

Eg the current situation is: 例如,当前情况是:

$ svn [tab]     - lists the svn commands

and: 和:

$ mything svn [tab]  - my completion needs to hand-over to svn's completion

but svn in the example above may be pretty much any bash command. 但是上面示例中的svn几乎可以是任何 bash命令。

As per my comments above, I've answered my own question! 根据我上面的评论,我已经回答了我自己的问题!

After doing "complete -p | grep time" , we can see how that command does it - you just need to define a completion rule as follows: 完成"complete -p | grep time" ,我们可以看到该命令是如何执行的-您只需要定义一个完成规则,如下所示:

complete -o filenames -F _command mything

and put it into an otherwise empty a file called /etc/bash_completion.d/mything . 并将其放入否则为空的名为/etc/bash_completion.d/mything的文件。 When you open a new bash terminal, you should then find that your mything command can complete any subcommands in the normal manner. 当您打开一个新的bash终端时,您应该发现mything命令可以正常方式完成任何子命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM