bash: some useful terminal commands

I found myself constantly needing to repeat some tasks from the terminal: open pages in chrome from the terminal. Open folders, especially bin. Run a simple python http server and give it a specific port. And setup watching and mapping on CoffeeScript files.

So here’s some bash scripts to do those things. I named mine chromeopen, openbin, pserver, and coffeewatch. chromeopen takes a single file name, and pserver will run using the port number if one is provided.

#!/bin/bash
open -a Finder /usr/local/bin
#1/bin/bash
if(($# != 1))
then
  echo "Requires a filename to open"
  exit 1
fi
open -a "/Applications/Google Chrome.app" $1
#!/bin/bash
if [ "$#" -ne 1 ]
then
  python -m SimpleHTTPServer
else
  python -m SimpleHTTPServer $1
fi
#!/bin/bash
coffee --output compiled --map --watch --compile ./

bash: script for making bash scripts

I had been on a bash script kick, adding shortcuts to run coffee script watching, or SSH’ing into different places, and realized that I could just write a bash script that would create a basic script file, with all the file permissions, place it in my bin folder, then open it in sublime for me to add the relevant code. Obviously you can change the ‘subl’ command to open it in your editor of choice.

#!/bin/bash

if(("$#" != 1))
then
  echo "Requires Command Name as Argument"
  exit 1
fi

COMMANDNAME=$1

 pushd /usr/local/bin/scripts
 touch $COMMANDNAME
 echo '#!/bin/bash' > $COMMANDNAME
 chmod 755 $COMMANDNAME
 subl $COMMANDNAME
 popd