I had to reformat my MacBook Pro recently. I use it for the development of some sites, where my usual approach it to create a VirtualHost in Apache for the domain name prepended with "dev.", so for example "dev.forrst.com".
What I realised is, I manually add the relevant entries to my hosts file and my httpd-vhosts.conf file manually each and every time, and now I've got to re-import all of my old working version sites, this will become tedious. So, I've knocked up a quick shell script.
This is my first shell script that's not one line, so feel free to suggest any improvements if there's any to be made.
To use the script, simply create an alias in your .profile file. I used alias addvhost=/usr/local/bin/addvhost.sh. Then, just run it from a Terminal prompt:
Raw Code »
The script will then ask you for two pieces of information: a host name (i.e. dev.forrst.com) and the actual location of your files (the document root). Once you've entered these, it'll create entries in hosts and your httpd-vhosts.conf (assuming they're in the default locations).
Tested on Mac OS X 10.6 (Snow Leopard). Also, I'm not responsible if you brick your Mac!