Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Surprise! the shell suggests command line switches

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?

like image 958
flybywire Avatar asked Apr 22 '09 07:04

flybywire


People also ask

What is a command line switch?

A command-line switch is a modifier that is added to the .exe file. A startup file with a switch looks like this. outlook.exe /nopreview. In this example, a command-line switch has been added to the .exe file for Microsoft Outlook.

What does dot mean in CMD?

. (dot) runs a shell script in the current environment and then returns. Normally, the shell runs a command file in a child shell so that changes to the environment by such commands as cd, set, and trap are local to the command file. The . (dot) command circumvents this feature.

What is a dot sh file?

A file with . sh extension is a scripting language commands file that contains computer program to be run by Unix shell. It can contain a series of commands that run sequentially to carry out operations such as files processing, execution of programs and other such tasks.

What is Bash source command?

The source Command The built-in bash source command reads and executes the content of a file. If the sourced file is a bash script, the overall effect comes down to running it. We may use this command either in a terminal or inside a bash script.


2 Answers

You have discovered Bash's programmable completion feature.

like image 89
unwind Avatar answered Oct 19 '22 09:10

unwind


See:

$ man bash

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

like image 25
Alnitak Avatar answered Oct 19 '22 08:10

Alnitak