#!/bin/bash # Copyright by # Scott D. Anderson # scott.anderson@acm.org # Released under the GNU General Public License # The TW software is fully contained in its directory tree: it doesn't # insinuate itself into other parts of your computer. However, compiling # using the TW Makefile is annoying without an alias, so this script adds # an alias to your login script # This script assumes that it is called with the TWHOME directory as its first arg # Note that aliases are shell-specific, so you have to *source* this # script in the shell that you want to have the alias, not execute it. # Can't exit in this script, because we are sourcing it! if [ $# -eq 0 ]; then echo "Usage: source add-alias TWHOME" else export TWHOME=$1 echo "TWHOME is ${TWHOME}" alias make-tw="make -f ${TWHOME}/Makefile " # Add the environment variable and alias to the ~/.bashrc, so that # every new shell gets it. Technically, the environment variable # should go in ~/.bash_profile, but this is fine and reduces the # number of files we are messing with. if [ ! -e ~/.bashrc ]; then echo 'export TWHOMEDIR=${TWHOME}\nalias make-tw="make -f ${TWHOME}/Makefile "' > ~/.bashrc else # checking with grep makes this idempotent, but it means that # erroneous aliases don't get over-written. if ! grep 'make-tw' ~/.bashrc > /dev/null ; then echo "adding the alias" echo alias make-tw="make -f ${TWHOME}/Makefile " >> ~/.bashrc else echo "alias is already there." fi fi # end the main enclosing if fi