|
mac geekeryGet your geek on. |
intelligent completion in bashNovember 12, 2005 - 8:05pm
A recent hint at macoshints shows how to create a shell script that will make all the Applications on your system available with tab completion. I’ve gotten used to Quicksilver and was interested in how this replicates some of that idea in the shell. But when I started looking through the comments there were some subleties and it got a bit complicated. I started poking around thinking of how I wanted to get this going and ended up finding something rather nice. Apparently, programmable completion has been around in bash for a while (via the shell builtin complete), but it needs to be scripted. However, there are some powerful scripts/packages floating around to demonstrate it’s capabilities. I like fink, and sure enough, fink has a bash-completion package. Here’s what I had to do to get it working: fink install bash-completion Added the following lines to my .bashrc file: source /sw/etc/bash_completion bind '"\t":menu-complete' The first line calls the bash-completion script that fink installed (make sure you source it after any lines that affect PATH’s), and the second line enable single-tab completions. This makes a Tab display the first possible completion, another Tab display the next, and so on, instead of the default double-tab-ask-first list. Once this is turned on, it not only completes commands and flags for many commands, but it can complete gui apps open -a (TAB) including ones it finds in Developer (it found xcode), complete ssh and scp (from known hosts), like ssh [username@](TAB) and man pages the same way, and etc … I wish there was a man file to enumerate more of what it does, but the /sw/etc/bash_completion file is pretty well commented, so we can see what exactly it completes, and how. There’s a LOT! Neat stuff like directory commands only see directories, user commands only see users, network interface completion, man completion … The fink package installs that script, and also a folder /sw/etc/bash_completion.d/ that contains some more scripts, most of which seem to be custom for mac, like open.sh and fink.sh. I looked at the open script and right at the top is the search path. It was trivially easy to add extra places for it to look for apps. I added my games folder where I keep some apps separate. Seems easy enough to add more scripts too. It’s crazy, my Terminal just got a whole lot smarter, and it will take me a while to catch up. Unix heads always had all this stuff ages ago, but sometimes I guess they forget to let us know. As far as other systems, Debian seems to include the bash completion scripts in its base install, all you have to do is uncomment a couple of lines in the default .bashrc to get it running. And it’s available in cygwin and rpm form as well. About 31d1 |
|
||||
Progmatic Tab Completion In Bash
—
cp