In Linux, when you run a program through bash, you can use Tab to speed up the input of parameters that need to be transferred to this program. How to make auto-completion work in my program?
- tldp.org/LDP/abs/html/tabexpansion.html - aleksandr barakin
- habrahabr.ru/post/115886 - don Rumata
2 answers
microsample.
let's do for our (non-existent) program autocompletion of options -a , -b and parameter c :
$ complete -W "-a -bc" x check. enter x , then a space, then the tab character twice and see the proposed options:
$ x <tab><tab> -a -bc In order for this to work in each session, the ( complete ... ) command can be added to the end of the ~/.bashrc .
to autocomplete file / directory names, you can, for example, add the -f option to the complete command:
$ complete -f -W "-a -bc" x and then you need to read the documentation ( https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html ) and look at the examples (with the current versions of the bash / bash-completion package - in the directory /usr/share/bash-completion/completions/ )
as an option you can see examples in the directory
/etc/bash_completion.d/* The 16 UBUNTU autocomplete programs are located in the directory
/usr/share/bash-completion/completions/ More details here.