简体   繁体   English

如何为函数启用bash自动完成功能?

[英]How to enable bash auto-completion for a function?

I have read this tutorial on bash auto-completion An introduction to bash completion and I am trying to get the same auto-completion that is already done for ssh for one of my functions (that is loaded from .profile ); 我已经阅读了关于bash自动完成这个教程bash完成的介绍 ,我正在尝试为我的一个函数(从.profile加载)获得已经为ssh完成的相同的自动完成; which acts pretty much as an alias . 它几乎就像一个别名

What I am trying to do is : get the same auto-completion, that is provided by default for ssh (which is the function _known_hosts ; do complete -p | grep ssh and you will get complete -F _known_hosts /etc/init.d/ssh ), and get it for my own function (which is installed like you woul install an alias, and that in fact does a scp and then an ssh with the original argument) 我想要做的是:获得相同的自动完成,默认为ssh (这是函数_known_hosts ; complete -p | grep ssh ,你将得到complete -F _known_hosts /etc/init.d/ssh ),并为我自己的函数(它安装就像你安装一个别名,这实际上是一个scp ,然后ssh与原始参数)得到它

The completion function for ssh here is _ssh . 这里ssh的完成函数是_ssh

You can see this with complete -p ssh (it should also have been in your grep output) though it appears to be auto-loaded and so will not show up until after you have used it once in that session. 您可以通过complete -p ssh (它也应该在您的grep输出中)看到这个,虽然它似乎是自动加载的,因此您在该会话中使用它之后才会显示。

Anyway, that being said you should just be able to hook _ssh up to your function as well I would think. 无论如何,据说你应该能够将_ssh连接到你的功能,我想。

complete -F _ssh myfunc

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

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