Bash completion for Mac app aliases

[Tweet : ADN : nvALT]

This one is simple but nifty.

I have a slew of aliases that launch various apps. Quite a few of them launch apps that I generally only use with one type of file. Xcode and TaskPaper, for example. I wanted a completion system that would find just the applicable files in the directory. In most cases with these apps there’s only one file per project, so being able to type xc and hit tab to open the xcodeproj file for the current project is handy.

Documentation on complete and compgen isn’t great, so it took me a while to figure out what should have been pretty simple. I got it, though, and I like the results.

Here’s the script. You’ll want to modify it to add the applications and aliases you want, but it’s simple enough that it shouldn’t take a lot of explanation. Add some aliases at the top (examples in the comments), build out case statements for them, and then make sure they’re all listed in the complete command at the bottom. Happy tabbing.

Ryan Irelan has produced a series of shell trick videos based on posts. Readers can get 10% off using the coupon code TERPSTRA.