Let’s be lazy!

After reading Be Lazy I came up with this question: could I write a Terminal function that loads projects environments?

First, I had to find out if writting custom commands was even possible. And yes, it is. I got some information from this article.

What I want my command to do:

  1. Go to the project directory in the Terminal
  2. Open the project files in Espresso (my text editor)
  3. Go to localhost on the browser (Safari)
  4. Launch MAMP

In less than a minute, I had a function running to do this. Now I just have to launch Terminal and type load my-project and there it is, everything I need to work on my project.

Here’s the function:

cd ~/path/to/your/projects/directory/$1;
open -a espresso $1.esproj
open -a mamp
open -a safari http://localhost:8888

If you want to use this or create your own, simply launch the Terminal, open .bash_profile on your text editor, and paste this function somewhere. Of course, you should write your own project routes and change "espresso" or "safari" to the actual apps you use. Also, my li’l function assumes that your project directory and your Espresso project are named the same. But well, you already noticed this, didn’t you?


January 2, 2013