bash programmable tab completion

After reading about bash a bit more I decided to make the switch. It’s been surprisingly painless considering just how long I’ve been running tcsh more or less exclusively since I learned the joys of FreeBSD way back at version 4.1 (okay, so it’s not /that/ long ago).

The main incentive was to get that funky programmable tab completion working. Everybody all over the place should investigate whether or not it can be of use to them. What I’ve done is fairly simple—allowed bash to use a NIS+ lookup (via the nisgrep command) to provide the necessary information to drive tab completion.

For example, in our labs the host naming scheme is fairly straightforward: arch-type-no-geo. So a host might be: v4u-10-e-gmp03. That’s the fifth SPARC Ultra 10 in my building. Normally we ping this by typing the command out, but with my simple script we can tab complete. This isn’t a massive time-saver, but every little helps.

It’s also very handy to be able to do:

$ v4u-10[TAB][TAB]

to get a listing of all of the Ultra 10s we have in the lab.

At a later point in time I’d like to tie this in to our booking system and maybe allow more powerful completion in a similar way to bash’s history search (CTRL+R) to allow us to just type ping 10-e[TAB] to get ping v4u-10-e-gmp03.

A word of warning: don’t forget to update tcsh’s ASCI escape sequences to the bash-style ones. I had an annoying cursor wrap that was driving me crazy for about a week until I bothered to fix it.

Tags:

Leave a Reply