Bash complete, and other colourful fun

One of the attrac­tions of Blue­host, my host, is the abil­ity to ssh into your box, which makes admin­is­ter­ing your site that much easi­er if you know how to use the *nix com­mand line. (See related post.)

I’ll just write about two things that I’ve worked out recently.

Les­son #1: Read the README file.

Well duh, you say. The story is, I’ve had the bash_​completion script for some time (a really use­ful exten­sion that makes typ­ing on the com­mand line that much easi­er), but I’ve nev­er quite worked out why it didn’t work. Now I know why. It’s because I naively assumed that the script was the meat of it, and simply called it from .bashrc, expect­ing it to just work. It would, ordin­ar­ily, but I don’t have it installed in /etc which is where it expects to be (it’s in my home dir­ect­ory). If you have some­where else like me, you will need to set the $BASH_COMPLETION vari­able and modi­fy the script to reflect where you’ve actu­ally put it.

Les­son #2: If you didn’t set up the sys­tem your­self, things might not be as you expect them to be.

SUITS has a bunch of use­ful scripts that you can use to improve your com­mand line exper­i­ence on the under­gradu­ate IT serv­ers, and I copied them over to my account on nointrigue​.com because I like them so much. One of these scripts sets nice col­ours for the com­mand line. It was all work­ing fine until I real­ised Tor­toiseS­VN could no longer access the Sub­ver­sion repos­it­or­ies via svn+ssh, fail­ing with the error “con­nec­tion closed unex­pec­tedly”. I figured some­thing I added recently was inject­ing garbage into the stream. It turns out it was the col­our-adding script! But why? It was pro­tec­ted like this:

if [ -n "$PS1" ]; then
        . ~/.bash/colors

That means that it should only have been run if it was run­ning in an “inter­act­ive” ter­min­al, and the col­our-adding script should not have been called if I was using svn+ssh. After some more pok­ing around, I found this in /etc/bashrc (which was being called from .bashrc):

# For some unknown reason bash refuses to inherit
# PS1 in some circumstances that I can't figure out.
# Putting PS1 here ensures that it gets loaded every time.

Uhh, ok, nice work, Blue­host. I guess not many of their cus­tom­ers actu­ally use ssh. At least there was a com­ment.

But even if it was called, why the col­our-adding script was fail­ing in the first place? It turns out that tput colors fails if $TERM is not set, which hap­pens to be so when using svn+ssh. (Actu­ally, this would not nor­mally pre­vent me from access­ing my Sub­ver­sion repos­it­or­ies. The com­mand line svn seems to ignore errors; how­ever, Tor­toiseS­VN dies the moment it sees any­thing unto­ward.) My ulti­mate solu­tion was to simply pipe error to /dev/null.

Tags: , , , ,