Getting bash Completion Magic on OS X

Paul R. Brown @ 2008-06-25T07:18:06Z

One of the many nifty features of bash is that it provides context-sensitive completion, but for some reason this capability isn't part of the bash that ships with Mac OS X, at least as of 10.5.3, which is what I'm presently using.

To rectify the oversight, first install the bash_completion port via MacPorts:

$ sudo port install bash-completion

And then modify your ~/.profile as directed, e.g., by adding:

if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
fi

To load your own local collection of completion hooks, create the directory ~/.bash_completion.d and then put the following in ~/.bash_completion (essentially cut/pasted out of /opt/local/etc/bash_completion):

if [ -d $USER_BASH_COMPLETION_DIR -a -r $USER_BASH_COMPLETION_DIR -a \
     -x $USER_BASH_COMPLETION_DIR ]; then
        for i in $USER_BASH_COMPLETION_DIR/*; do
                [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|.rpm*) ]] &&
                        [ \( -f $i -o -h $i \) -a -r $i ] && . $i
        done
fi
unset i

Next, above the other block added to ~/.profile, add:

export USER_BASH_COMPLETION_DIR=~/.bash_completion.d

As for the contents of .bash_completion.d, I put the completion files supplied with darcs and cabal-install there, so in addition to the usual niceties like completion of paths on remote servers (e.g., for scp), I also get convenient completion behavior at the commandline, e.g., with cabal:

$ cabal install hsc[TAB]
hsc2hs hsc3 hsclock hscolour hscurses
(comment bubbles) 0 comments

Darcs Repository for Perpubplat

Paul R. Brown @ 2008-01-04T08:45:59Z

I succumbed to some mild peer pressure, posted a Darcs repository, cleaned-up the Cabal files for perpubplat, and fixed a few minor bugs. If you have darcs installed, you can pull down a copy of the source code — a grand total of less than 1500 lines according to SLOCCount — with:

darcs get http://datapr0n.com/repos/perpubplat

You can also browse the repository at the same URL, but Apache will serve those files to you as text/x-haskell, i.e., your browser probably won't display them as plain text in the browser. The Darcs-maintained revision history is here.

The README file contains instructions on building, but if you've already got GHC 6.8.2 and FastCGI libraries installed, it's as easy as:

$ cd perpubplat
$ cd perpubplat
$ chmod +x Setup.lhs
$ ./Setup.lhs configure && ./Setup.lhs build && sudo ./Setup.lhs install
$ cd ../perpubplat_servlet
$ ./Setup.lhs configure && ./Setup.lhs build

The FastCGI handler is dist/build/perpubplat.fcgi/perpubplat.fcgi.

(comment bubbles) 0 comments