DEV Community

Cover image for My Terminal Setup: iTerm2 + Zsh ๐Ÿ”ฅ
Ali Spittel
Ali Spittel

Posted on • Edited on • Originally published at zen-of-programming.com

My Terminal Setup: iTerm2 + Zsh ๐Ÿ”ฅ

As a follow up to my post on my text editor setup, I wanted to write about the other key part of my development setup -- my terminal. Unlike my relatively new text editor setup, my terminal configuration has followed me around for years -- spanning over multiple jobs and even more computers. It's the first thing I get set up on when I get a new computer

The Terminal

I use iTerm2 for my Terminal emulator. It has some really cool features, like search, autocomplete, and paste history. That being said, the feature that makes it a complete must have for me is the split panes.

My Terminal

When I do web development work, I usually have panes open for my server session and for running other commands as necessary. When running many processes at a time, as was required at my old job, I would easily have 10 panes open at a time

Lot's of sessions

You can use the shortcut cmd + d for a new pane horizontally, and cmd + shift + d for a new vertical pane.

my terminal colors

I do have some tweaks to the color palette that I use -- I think the biggest is that my default font is pink (the forefront color).

Other than that, most of the "magic" comes from my shell, Zsh!

The Shell

For my shell, the programming language the command line uses, I use Zsh instead of Bash.

There are some pros and cons of using Zsh, the biggest drawback I've found is some difficulty installing certain software. This was a big learning curve at first, but over time I've gotten used to common stumbling blocks and don't have as many problems. Taking this into account, I would only recommend Zsh for experienced shell users!

That being said, the pros for me far outweigh the cons. The tab completion is much better in Zsh as compared to Bash. It even has tab completion for Git!

Oh My Zsh is a framework for managing your Zsh configuration, and it is a must download. When I refer to Zsh, a lot of the features are actually a part of Oh My Zsh.

My .zshrc

Instead of a .bash_profile, Zsh primarily uses a .zshrc file where your customizations are saved. By default, there are a bunch of comments explaining different settings in that file. I am going to go through some of my settings below.

Zsh has awesome themes, which change the appearance of your prompt.

I use Spaceship which displays a bunch of excellent information. For example, in the directory for my blog, which is a node app, my git branch, the git status, the package version, and the current Node version display. Also, it shows the amount of time the previous command took to run and the computer battery percentage if it is low! This changes slightly from directory to directory, but its really nice to have this information so accessible, especially compared to how difficult it can be to create something similar in a Bash environment.

I am always switching on and off the auto-correct built into Zsh. Right now I have it turned on, but it does sometimes annoy me.



ENABLE_CORRECTION="true"


Enter fullscreen mode Exit fullscreen mode

Another excellent Zsh feature is plugins. These make Zsh have better autocomplete for different languages or add additional features to the shell. I especially recommend the git plugin -- it's what gives you tab completion for git! I also really like zsh-syntax-highlighting. It highlights valid commands green and invalid ones red, so you don't even have to test the command to see if it will work!



plugins=(git node bundler osx rake ruby python javascript bash zsh-syntax-highlighting)


Enter fullscreen mode Exit fullscreen mode

After that, I have boring PATH and git configuration, so I'm going to leave that out.

Finally, we get to my aliases and custom functions. My guilty pleasure function that isn't great practice is entitled "acp". "acp" adds, commits, and pushes my code, and it looks like this:



function acp() {
  git add .
  git commit -m "$1"
  git push
}


Enter fullscreen mode Exit fullscreen mode

I use it way too much, but it really speeds things up when I'm working on personal projects.

I have two custom aliases setup:



alias groups="python ~/wdi/groupr/groupr.py"
alias zen="gatsby build && surge public/ zen-of-programming.com"


Enter fullscreen mode Exit fullscreen mode

The first creates random groups of my students for in-class activities and projects. Zen deploys my personal site. Yes, I only have two custom aliases; however, that is just because so many are built into Oh My Zsh!

Some built-in ones I rely on especially hard are "..." which is an alias for "cd ../..". You can keep adding periods and keep moving back in directories. You can also omit "cd" and just type the file name to change from one directory to another -- "blog" is equivalent to "cd blog." There are also other aliases built in to do almost anything you could dream of with git. I also enjoy please=sudo, even though I don't personally use it!

Another bonus utility I have on my computer is tree (which you can install on a Mac with brew install tree). This lists the folders and files in a directory in a really nice way.

file tree

Don't be a stranger!

If you liked this article and want to read more, I have a weekly newsletter with my favorite links from the week and my latest articles. Also, tweet me a picture of your terminal setup!

Top comments (66)

Collapse
 
wolfhoundjesse profile image
Jesse M. Holmes

I love oh-my-zsh!

Everyone loves their splitting, multiplexing terminals, but I tried something different this timeโ€”Iโ€™ve been using i3wm for almost a year, and I really like it. If I need a new pane, I just pop open a new tile.

Iโ€™ve never asked if there is a difference between the two. Am I missing out by not using a multiplexer?

Collapse
 
ben profile image
Ben Halpern

Aside from feature sets, I really rely on love stories when picking out my dev tools.

oh-my-zsh! is one of those things I can't ignore the love for. I'm going to finally give it a dive.

Collapse
 
aspittel profile image
Ali Spittel

Yessss! it's amazing

Collapse
 
defman profile image
Sergey Kislyakov

I remember it being kinda slow. I'd recommend using zgen and loading only what you need from OMZ.

Collapse
 
robbyrussell profile image
Robby Russell ๐Ÿ˜๐Ÿš‚

Thanks for loving Oh My Zsh! <3

Collapse
 
benjaminrood profile image
Benjamin Rood

Thank you for all your continued work on it, Robby!

Collapse
 
kungtotte profile image
Thomas Landin

On my Linux box I'm using Awesome WM, but it's the same principle. Why muck around with terminal panes when you have a whole window manager designed specifically for handling windows?

Bonus feature is that you can use any terminal you like without relying on it supporting panes/windows internally.

You typically also get multiple desktops with a window manager (called tags in awesome), so you can have a bunch of sysadmin terminals up on one tag and then either hit mod4+left/right to scroll to the next or hit mod4+number to jump to a specific one. I have mine set up to always open Firefox in a specific tag for example. You can configure different layouts for different tags, and swap layouts on the fly (awesome is a dynamic WM so it supports both tiling and floating windows).

Another bonus feature is it tiles/handles any type of window, not just terminals. So if you want two terminals, a gedit, and a browser up at the same time they all get tiled into the right place.

Collapse
 
benjaminrood profile image
Benjamin Rood

There's advantages of working in either way, but I'm looking forward to installing Awesome on my machine soon.
I think if you prefer to work on macOS Ali's way + a window management tool (BetterSnapTool is my favourite) is probably ideal.

Collapse
 
moopet profile image
Ben Sinclair

Yes - if you want to switch to a different session with a keyboard shortcut you have to use generic WM shortcuts and more importantly if you're on a foreign system and create a new terminal it'll be local. With a multiplexer it'll be logged into the remote system (and just as disconnectable as your original session)

Collapse
 
wolfhoundjesse profile image
Jesse M. Holmes

Oh, this! I remember, itโ€™s just been a while. Thanks!

Collapse
 
sudiukil profile image
Quentin Sonrel

Same here for i3!

Collapse
 
mrquinn profile image
Michael

In case it's not clear, tree is not a shell built-in, it's the name of an external program (e.g. /usr/bin/tree.) Therefore it doesn't matter what shell you're using; either the program is installed or it isn't. Apt-get install tree, or brew install tree, or whatever other tool you use to install apps use that to install tree. ;)

Collapse
 
moopet profile image
Ben Sinclair

There's git tab-completion in bash as well if you turn it on.

I think that zsh has things to offer, but the things most people seem to talk about are available in bash if you want anyway. Zsh has some cooler globbing, but that's about it for me. I prefer to know bash well since it's much more likely to be the shell I'm using on a foreign system.

Collapse
 
stacy profile image
Stacy Montemayor

This is super timely for me! I just started fiddling with my terminal last week for the first time (I'm just starting to learn to code.) I upgraded to iTerm and like some of the features already. I'll be saving this to return to and read as I start to understand more.

Does anyone have any recommendations on an article or video for total newbie programmers setting up their terminals? Maybe more of a high-level overview?

Collapse
 
caiuscitiriga profile image
Caius Citiriga

Here you go! Hope you find it useful.

laracasts.com/series/setup-a-mac-d...

Collapse
 
stacy profile image
Stacy Montemayor

Thanks! I like his style too - I'm going to check out other videos.

Thread Thread
 
caiuscitiriga profile image
Caius Citiriga • Edited

You're welcome!

The guy speaking is Jeffrey Way. One of the most advanced Laravel's users. He's even a Laravel contributor for what I know, along with Taylor Otwell who's the actual creator.

Btw, Laravel is a PHP framework (a pretty robust one tho!)
On Laracasts you can find a lot of videos on Laravel of course, but there are a lot of other topics that doesn't concern the framework and still can be very helpful.

Like: Git me some version control, or "stand back i'm going to try regex", vue2, flexbox etc.

Some free some under subscription. But still, the free material has the same quality as the paid one.

Collapse
 
robbyrussell profile image
Robby Russell ๐Ÿ˜๐Ÿš‚

I'm so delighted to see you mention Oh My Zsh in this article. Thanks for helping spread the word. :-)

Collapse
 
aspittel profile image
Ali Spittel

Ahh thanks for reading!! And for Oh My Zsh, it's amazing!

Collapse
 
nickytonline profile image
Nick Taylor

Fish autocompletion was what sold me on fish, but since hearing about Apple using zsh as the default terminal in the next major OS version, I decided to try zsh again. I got it setup fairly easily and I found a plugin that does the same thing as fish autocompletion, so switching back to zsh has been pretty transparent.

For those interested, here's the plugin.

I think I will have to update my Mac setup

or just do a write up on my zsh setup. ๐Ÿ˜‰

Collapse
 
mrquinn profile image
Michael • Edited

I love .oh-my-zsh and the plugins. Ie: git, sudo, z, colored-man-pages & dirhistory. I have used Konsole on Mint since 16 & now 19.

Collapse
 
robbyrussell profile image
Robby Russell ๐Ÿ˜๐Ÿš‚

Thanks for sharing your favorite plugins, Michael!

Collapse
 
mrquinn profile image
Michael

Thank you for all your hard work making Oh-my-zsh such a gr8 add on for my nix boxes... it's a pleasure to use!

Collapse
 
tvanantwerp profile image
Tom VanAntwerp

Nice! I'm also iTerm + oh-my-zsh, using Powerlevel 9k for custom theme. I don't use panels--I've always just used tabs, as I keep the terminal window in a small corner of my workspace. I don't feel like it's made much difference.

Screenshot!

Tom's Terminal

Collapse
 
benjaminrood profile image
Benjamin Rood

Nothing to stop you using panes and tabs together!

Collapse
 
mrgnw profile image
Morgan • Edited

Yay!
Avit-pure is my fav oh-my-zsh theme, this is my version with a couple of tweaks:
github.com/mrgnw/mzsh/blob/master/...

(Like if you're in SSH it'll show ๐Ÿ“ก so you don't accidentally mix up sessions)

Collapse
 
phantomhaze profile image
Alex Hernandez

A fellow spaceship user!

I may have to post about my own setup now, which selects a random prompt character each session. ๐Ÿš€โ˜„๏ธ๐Ÿ™ˆ๐Ÿ•

I did not know about the '...' alias! I may have to dig my hands into the zsh alias's, after seeing how it's improved your workflow.

Thanks for the article!