Ads Top

Developer Workflow Tools: Using iTerm2 on OS X

The terminal in OS X is obviously very useful as a developer. I've known about a program called iTerm2 for a while but never switched over to start using it. It is increasingly often that I am working on multiple projects and have many tabs open in my terminal. I also flip back and forth between between 2 tabs displaying a client and server setup. I wanted a simpler view to help handle this.

Enter iTerm2
** Notice I keep saying iTerm2. That is because iTerm2 is a "fork" of the original iTerm

iTerm2 is a terminal emulator for OS X. In saying terminal emulator, that is essentially saying it is an application that is made to look like the existing application but extends functionality.

If you are interested in a list of features as to what iTerm2 can do check the iTerm2 List of features

My Current Setup (basic)
As I mentioned above, my main goal was to deal with multiple windows being open at the same time. I added these configurations to my iTerm2 setup as detailed below

Before that, if you want to download iTerm2, you can go to the downloads page. After you install it, you can start using it just as you would use the regular Terminal application.

Get current directory to display in the tab
This setting allow you to see the current directory you are in when you have 1 or multiple tabs open in iTerm2. This is very helpful with more than one tab for obvious reasons.

In your terminal do the following
nano ~/.bash_profile Enter the following or copy/paste
## Current in directory iterm tab
if [ $ITERM_SESSION_ID ]; then
  export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
Once you do that, either close and reopen the terminal or enter
source ~/.bash_profile (or if in that directory source .bash_profile)

Split Pane Shortcuts
Another powerful feature is the ability to split windows. This feature allows you to split the pane vertically and horizontally. Notice in the screenshot below, I am viewing one pane with the same project open but displaying server side of the project on the left and the client portion on the right. With this I can run the server and view its status, while at the same time looking at the server structure without having to flip tabs.

Horizontal Split:
command + d + shift
Vertical Split :
command + d vertical
** you can split multiple times and mix between horizontal and vertical

Close split panes:
command + w
** if you hit too fast it will close iTerm2 itself if all other panes are closed

Toggle Beween Split Panes:
command + [
command + ]

One of the issues I had was if I closed iTerm2 and reopened it, it would open a new session with none of the windows I had open from the previous session. It turns out that this was an OS X setting I had to adjust for this to work for me.

In OS X System Preferences, go to General. Once there, remove the check from 'Close windows when quitting an app' (note, this will affect other apps to such as your browser)

These are just some things you can do within iTerm2, I barely touched on them because of the limited scope of the problem I was trying to solve for me, I again suggest taking a look at the feature list and giving it a try if you think it would be useful.

No comments:

Powered by Blogger.