bash 惊喜!shell 建议命令行开关
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/776071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Surprise! the shell suggests command line switches
提问by flybywire
I noticed that the bash shell can suggest command line switches for your command.
我注意到 bash shell 可以为您的命令建议命令行开关。
Just type your command, a dash (-) and type tab. The shell will show you available switches.
只需输入您的命令、破折号 (-) 并输入制表符。shell 将显示可用的开关。
For example, try:
例如,尝试:
andy@andyx:~$ java -
and press tab - Surprise!
然后按 Tab - 惊喜!


The question is:
问题是:
How do I interface with this feature. I.e., if I write a program that is to be run from the console, what's the API to tell the shell what switches are available?
我如何与此功能交互。即,如果我编写了一个要从控制台运行的程序,那么告诉 shell 哪些开关可用的 API 是什么?
回答by unwind
You have discovered Bash's programmable completionfeature.
您已经发现了 Bash 的可编程完成功能。
回答by Alnitak
See:
看:
$ man bash
In particular, the section entitled "READLINE" and subsection "Programmable Completion"
特别是标题为“READLINE”的部分和“Programmable Completion”小节
回答by Alnitak
FYI: In Ubuntu and/or Debian the scripts are at /etc/bash_completion.d/
仅供参考:在 Ubuntu 和/或 Debian 中,脚本位于 /etc/bash_completion.d/

