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 easier 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 easier), but I’ve never quite worked out why it didn’t work. Now I know why. It’s because I naively assumed that the bash_completion.sh 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 modify the bash_completion.sh 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­toiseSVN 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 colour-​​adding script! But why? It was pro­tec­ted like this:

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

That means that it should only have been run if it was run­ning in an “inter­act­ive” ter­minal, and the colour-​​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 comment.

But even if it was called, why the colour-​​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­toiseSVN dies the moment it sees any­thing unto­ward.) My ulti­mate solu­tion was to simply pipe error to /dev/null.

Tags: , , , ,

Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>