Surprise! the shell suggests command line switches

2019-03-17 23:30发布

I noticed that the bash shell can suggest command line switches for your command.

Just type your command, a dash (-) and type tab. The shell will show you available switches.

For example, try:

andy@andyx:~$ java -

and press tab - Surprise!

Screenshot

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?

3条回答
欢心
2楼-- · 2019-03-18 00:25

FYI: In Ubuntu and/or Debian the scripts are at /etc/bash_completion.d/

查看更多
小情绪 Triste *
3楼-- · 2019-03-18 00:27

See:

$ man bash

In particular, the section entitled "READLINE" and subsection "Programmable Completion"

查看更多
再贱就再见
4楼-- · 2019-03-18 00:29

You have discovered Bash's programmable completion feature.

查看更多
登录 后发表回答