A Bash Completion Script for SCons

The Problem

SCons is a build tool that uses Python as the underlying scripting language. Tools like SCons, Rake, Rant (Rake and Rant use Ruby as the underlying scripting language), Gradle, and Gant (Gradle and Gant use Groovy and the Ant tasks) show that using scripting/dynamic languages to create domain specific languages (DSLs) is the way forward for build technology. Systems such as Make, which were revolutions in their time have been superceded by the systems that they inspired. A natural evolution.

I have been using SCons as the build tool for a C++ project and also a LaTeX book. It works very well for both of these having direct support for building C++ programs and LaTeX programs on a very wide variety of operating systems – I use Debian and Fedora.

I have, however, had a real irritation: SCons had no support for Bash completion. I also use Rake as the build tool for a couple of other things and its support for Bash completion is just so useful and supportive.

The Solution

The solution is totally clear: create a Bash completion script for SCons (also for Gant but that is another story). After looking at the scripts for Rake and Subversion and some experimentation with SCons, I came up with a script (that you can download by clicking here) that seems to do the job. It almost certainly has errors and/or bugs but for the moment it "works for me";.

To use this script you can do one of:

  • Ensure you have a ~/.bash_completion file that includes all the scripts in a personal Bash completion script library. I have a directory ~/bash_completion.d in which I put the various scripts – copying directly the way that Bash organizes scripts in /etc. My ~/.bash_completion file then contains a copy of the relevant bit of the system script:
# -*- mode:shell-script -*-
for file in bash_completion.d/*
    [[ ${file##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|.rpm*) ]] &&
    [ \( -f $file -o -h $file \) -a -r $file ] &&
    . $file
  • Append the contents of the file to your ~/.bash_completion file.
  • Put the file in /etc/bash_completion.d with all the other system-wide scripts.

The last has the advantage of working for all users of the machine but does require super-user privileges. I use the first as being the easiest.

Do email me if you have any feedback.

Copyright © 2005–2020 Russel Winder - Creative Commons License BY-NC-ND 4.0