An Introduction to Programmable Completion
The programmable completion feature in Bash permits typing a partial command, then pressing the [Tab] key to auto-complete the command sequence. [1] If multiple completions are possible, then [Tab] lists them all. Let's see how it works.
bash$ xtra[Tab] xtraceroute xtrapin xtrapproto xtraceroute.real xtrapinfo xtrapreset xtrapchar xtrapout xtrapstats bash$ xtrac[Tab] xtraceroute xtraceroute.real bash$ xtraceroute.r[Tab] xtraceroute.real |
Tab completion also works for variables and path names.
bash$ echo $BASH[Tab] $BASH $BASH_COMPLETION $BASH_SUBSHELL $BASH_ARGC $BASH_COMPLETION_DIR $BASH_VERSINFO $BASH_ARGV $BASH_LINENO $BASH_VERSION $BASH_COMMAND $BASH_SOURCE bash$ echo /usr/local/[Tab] bin/ etc/ include/ libexec/ sbin/ src/ doc/ games/ lib/ man/ share/ |
The Bash complete and compgen builtins make it possible for tab completion to recognize partial parameters and options to commands. In a very simple case, we can use complete from the command-line to specify a short list of acceptable parameters.
bash$ touch sample_command bash$ touch file1.txt file2.txt file2.doc file30.txt file4.zzz bash$ chmod +x sample_command bash$ complete -f -X '!*.txt' sample_command bash$ ./sample[Tab][Tab] sample_command file1.txt file2.txt file30.txt |
Read full article from An Introduction to Programmable Completion
No comments:
Post a Comment