Every developer has spent probably more hours than they want trying to get a terminal or console to work for their development style. I know I have spent way to many hours on this task and I finally found a system that’s working for me.
The problem for me has always been how do quickly get into a development environment and start working when I get on my computer. Then how do I just as quickly tear that environment down knowing I can pull it up quickly the next time I need it.
Tools like Vagrant and other offer great ways to get the operational side of this development environment up but unless you want to work in a heavy IDE like Eclipse I’ve always struggled with the authoring side of this problem.
I know many of you are probably using SublimeText already so know what I’m talking about when it comes to getting up and running on a new project there. I’ve been asked by a few people though how do I just as quickly setup a savable environment in iTerm2.
iTerm2 breaks this into two parts Window Arrangements and Profiles so let’s get into setting these up for repeatable environments.
Profiles, Profiles, Profiles
Yep you’ve got to create a few profiles.
Open up the profiles menu from the iTerm2 preferences (cmd-,) go to the Profiles tab.
I start with creating a Previous Directory profile. This is my goto profile for most windows as it will automatically go back to the last place it was when your restore a session that has this profile.
Name it how you want.
The only setting you need to have is the radio for Reuse previous session’s directory under the Working Directory subsection.
I also setup profiles for each of my runnable tasks such as MongoDB.
For these you’ve got two things to set. First set the working directory by selecting the Directory radio from the Working Directory option and setting it to the directory you need run your command from
Window arrangements are the glue to a an easy environment in iTerm2.
To setup a window arrangement you must start from a blank slate, by this I mean close all open iTerm2 terminals (cmd-w).
Now we open the windows and start generating a dev environment. I’m going to walk through creating an environment for my current startup.
We’ll need runners for MongoDB, Redis, my application frontend server and my application backend server. We’ll also need a window for checking code in.
Create a new window (Shell -> New Window or cmd-n).
This is our canvas and now we’re going to draw the rest of the environment using the options to split pane.
I continue splitting vertically and horizontally until I have all the panes I need in an arrangements I like.
Note: you can drag the edge of any pane to resize it.
Next we’ll map these sessions to desired profile. Click on the little gear for each pane and select Edit Session.
Close this panel (the red button or cmd-w). Repeat for each pane.
Note: For the code pane I use the Previous Directory profile then move to the code directory before the next step.
Now we need to save this marvelous new environment by saving the window arrangement (cmd-shift-S or Window -> Save Window Arrangement). Enter a name and your done.
Let’s test that it works.
1. Close your arrangement
2. Window -> Restore Window Arrangement -> Your Arrangement
If you have further tips I’d love to hear about them in the comments section below.