Serve.sh updated for terminal use

After publishing the previous article about serve.sh – the shell script I created to easily serve websites in development – I made some changes to make it easier to run it from the terminal, for example over ssh. I thought I’d share it with you.

One of the problems with the original script was that it was optimized for a GUI setting – ie. start the script by clicking on it from the desktop. However usually I want to run it from the terminal. I don’t like typing so I added code to make the script available from any directory to the ~/.bashrc:

export PATH=$PATH:~/bin

Then moved it to that path and renamed it to shave another 3 characters off the syntax:

mv ~/Desktop/serve.sh ~/bin/serve

In addition I noticed that prompting which site should be served was just a workaround for commandline arguments, which are now added. It doesn’t check that you entered an argument though. So the new script now requires you to specify which directory you want to serve: to serve the current directory simply run:

serve .

Latest script contents:

#!/bin/bash
my_path=`readlink -f $1`
sudo rm /var/www
sudo ln -s $my_path /var/www
echo Now serving $my_path...

May 9, 2011 at 10:35 AM in Development, Linux

VanDragt.com is a collection and semi organised thought process on web, development and technology news by Sander van Dragt.