Setting up a development environment
Simplify

Since $# cannot be both 0 and 1 at the same time, it would be better to join the two if conditions here:


local a="$1"
if [ $# -eq 0 ]
then
    a="default"
fi
if [ $# -eq 1 ]
then
    git config --global user.name "$a"
    git config --global user.email "$a@$a.com"    
fi



But, actually, what if there are 2 or more parameters instead of 0 and 1? It can happen by a programming mistake. It would be more robust to rewrite this by checking the values of the parameters, rather than their total count:

if [ "$1" ]
then
    git config --global user.name "$1"
    git config --global user.email "$1@$1.com"    
fi


Notice that I eliminated the a local variable, as it was pointless (a="default" set but never actually used).

Avoid changing directories in scripts

This is a bit fragile:


cd ~/root_install/grunt
npm install
cd ~/root



A cd command may fail, for example if the directory was not yet created. In general it's not a good idea to change directories inside a script, as the script might perform actions in unexpected directories when things go wrong.

A good solution in such situations is to wrap commands within (...), like this:

(cd ~/root_install/grunt; npm install)


Directory changes executed inside (...) will not affect the environment outside.

You can learn more about this syntax in the Compound Commands section in man bash:


   (list) list  is  executed in a subshell environment (see COMMAND EXECU-
          TION ENVIRONMENT below).  Variable assignments and builtin  com-
          mands  that  affect  the  shell's  environment  do not remain in
          effect after the command completes.  The return  status  is  the
          exit status of list.



Robustness

Note that if you re-run the script a 2nd time, some commands will fail, for example these:


mkdir ~/root_install/grunt
ln -s ~/root/config/grunt/package.json ~/root_install/grunt/package.json
ln -s ~/root/config/grunt/Gruntfile.js ~/root_install/grunt/Gruntfile.js



If the directory and the symlinks already exist, the script will print error messages for these lines. You can avoid that by adding some flags:

mkdir -p ~/root_install/grunt
ln -sf ~/root/config/grunt/package.json ~/root_install/grunt/package.json
ln -sf ~/root/config/grunt/Gruntfile.js ~/root_install/grunt/Gruntfile.js


Naming

These variable names are not very helpful:


local a=$(which bash) b=$(which git) c=$(which grunt) d=$(which subl)
local g=$(which node)  i=$(which heroku)



Better name these after the commands they represent:

local bash=$(which bash) git=$(which git)  # and so on ...