Maybe you haven’t noticed, but Electric Make (emake) has a lot of command-line options. Besides the options it inherits from emulating GNU make (or NMAKE), it has about fifty of its own options, from –emake-annodetail to –emake-tmpdir. Remembering them all, and their exact spelling, and their allowed values is a nuisance, even for me — and I created half of those options myself. So, I spent the last few evenings hacking together Bash TAB completion support for emake (download from github here), with pretty good results:
$ emake --emake-h<TAB><TAB> --emake-history= --emake-historyfile= --emake-history-force=
In addition to helping with emake options, it can help me remember the valid values for those options:
$ emake --emake-history=<TAB><TAB> create merge read
It handles options with compounds values too, like –emake-annodetail:
$ emake --emake-annodetail=<TAB><TAB> basic env file history lookup registry waiting $ emake --emake-annodetail=file,<TAB><TAB> file,basic file,history file,registry file,env file,lookup file,waiting $ emake --emake-annodetail=file,history,<TAB><TAB> file,history,basic file,history,registry file,history,env file,history,waiting file,history,lookup
It can even do TAB completion on targets in makefiles, thanks to some clever code inherited from the gmake completion module that I used as the basis for my emake completion module:
$ emake <TAB><TAB> all check distclean Makefile buildtest clean install
And since I was already tinkering with TAB completion for emake, it wasn’t much work to do TAB completion for ElectricInsight (einsight) as well. In that case, TAB completion doesn’t really do a whole lot — einsight doesn’t have many command-line options. But intelligent TAB completion is still pretty handy for one specific reason: I can make it only match files with the correct extension — .xml and .anno:
$ ls build-272.dlog build-272.xml build-273.dlog build-273.xml $ einsight <TAB> $ einsight build-27<TAB><TAB> build-272.xml build-273.xml
Rather than suggesting all of the files in the directory, Bash now knows to suggest only the .xml files when I invoke einsight.
I was surprised to find that setting up custom TAB completion for my applications is pretty easy: just create a shell function that generates a list of possible completions based on a partial command-line, then instruct the shell to use that function to handle completions for whatever command you like. As far as I can tell, the mechanism is pretty flexible — you’re limited only by your own Bash scripting skill. If you’re interested in doing something like this yourself, I suggest you check out these online tutorials, as well as the Bash Completion project, which includes completion modules for nearly 200 commands.
Availability and installation
You can download the TAB completion module for emake and einsight from my github repository. As far as installation goes, you have a few options:
- Hook into the bash-completion package. Many modern Linux distributions, including Ubuntu 9.x/10.x and SUSE 11 install the bash-completion package and set up the default bashrc file to use it. On those systems, you can just copy accelerator.sh to /etc/bash_completion.d.
- Modify your personal .bashrc. If your system doesn’t have the bash-completion package, or if you can’t add files to etc, you can modify your own .bashrc to source accelerator.sh on startup. In that case I would rename it to $(HOME)/.accelerator.sh, so that it is normally hidden from directory listings, and add source $(HOME)/.accelerator.sh to your .bashrc file.
The image at the top of this post is free; you can redestribute it and/or modify it according to the terms of the Free Art License; it is based on this image by Aurelio Heckert.