Terminal shortcut for localhost

An OSX goody for fast development

Bruno Tavares

--

My Apache localhost points to /Users/brunotavares/, which means that http://localhost/Code/ProjectA maps to /Users/brunotavares/Code/ProjectA.

Being someone that likes the terminal, I decided to create a small helper where I could simply type “chrome” and have it open Google Chrome with the localhost pointing to the current directory. You know, save some time to actually open Chrome and type localhost/blablabla :)

Create this file under /usr/bin, adjusting to your localhost path

#!/usr/bin/env ruby
dir = Dir.pwd
dir.sub! “/Users/brunotavares”, “
http://localhost
exec ‘open “/Applications/Google Chrome.app” ‘ + dir

There you go! Now I can do this and have my project opened very fast:

cd ~/Code/ProjectA
chrome

I know there’s also scripts on the web to start a server from the current directory. I have this too, but I wanted to use Apache and the script above does the trick.

Enjoy :)

--

--

Bruno Tavares

I am a brazilian living in California and working as a Software Engineer. I like all things web, specially those beautifully designed.