Why, David? Why?
What kind of maniac would want to spend precious time customizing their terminal? Well, if you spend a lot of time there, like most software engineers and web developers do, it can be well worth your time. In this article I’ll breeze through some of the core tools you’ll need to create the above masterpiece.
The quest for the perfect terminal setup is an ongoing saga. A good setup may include answers to the following questions:
- Who am I?
- Which host am I on?
- Where am I?
- Am I inside a code repository?
- Which branch in the code repository am I using?
- Do I have changes that are not committed?
I don’t do a lot of bouncing around between users and hosts so I tend to eschew those bits in my prompt. You will notice that my setup does include the remaining items from our above list.
The basic terminal that comes with OSX is okay, very okay. However, iTerm2 has a slew of customization options that are very attractive. I probably only use five percent of what’s available but I love the customization of fonts, 256 colors, transparency, and other little bells and whistles. Some other features you may love are split panes, search, autocomplete, better hotkey support, and multi-lingual support.
Enough already! Just go download iTerm 2 and install it and thank me later. You can either get it at the iTerm2 website or get out your powerglove and install it with Homebrew:
brew cask install iterm2
Now we’re ready for some other big changes.
Zsh and Oh My Zsh!
The standard shell that you get with most operating system setups is bash. This is the default in OSX. However, there are many alternatives to it, one of the most popular being zsh. This is pronounced “zee shell” or for some, “zed shell”.
Oh My Zsh! is a framework for zsh that let’s you easily take advantage of plugins for commonly used applications. It’s one of the most popular repos on Github. You can hop over to the Oh My Zsh! website. Or you can jump right in and install it using this command:
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
We’re going to be using it largely for mining some data to use in our theme.
Download a sweet theme: Cobalt2
Oh My Zsh! has themes and we’re going to want to download the cobalt2 theme. Take the cobalt2.zsh-theme and drop it into ~/.oh-my-zsh/themes/.
Remember all those awesome icons in my terminal setup? We need some special fonts to enable those. Powerline is a set of open source fonts that support the special glyphs we want. You can download the Powerline fonts by going into a location where you’d like them installed in your terminal and running:
git clone https://github.com/powerline/fonts.git && cd fonts && ./install.sh
This will take a minute but it will download and install everything into a fonts fonts folder where you currently are in your directory tree.
Putting it all together
Now we’re finally going to piece this all together. Open iTerm2 and then open the Preferences menu.
Add the Cobalt 2 colors
Drag and drop cobalt2.itermcolors right onto your iTerm2 app. Now under Colors at the bottom you’ll be able click on Load Presets and choose cobalt2. Boom! Your terminal colors are now awesome.
Choose a compatible Powerline font
Under Text, choose a Powerline font for both your Regular Font and your Non-Ascii Font. I chose 13pt Meslo LG M for Powerline for both of mine. Many people like Inconsolata G for Powerline.
Set your zsh theme
Now to finish it off, edit your
~/.zshrc file with your favorite editor. Add this line somewhere and save it:
Now, to update your shell to use this new setting you can either close iTerm2 and re-open it, or you can enter this command:
Now you should see all of the changes that we made. It should look something like my terminal at the top. If you have a git repo, move into that directory to see your branch displayed and an indication of if you have uncommitted changes in yellow.
Congratulations, you now have an awesome terminal! You’ll probably want to do some more research on on-my-zsh theme options to tweak your terminal to your liking.
I’ve already made some cosmetic tweaks to my Cobalt 2 color theme to lower the contrast. The contrast between the status line text and background colors was too low for my liking so I lightened all the colors a bit. Also, I toned down the normal white text to lower the contrast to make it easier on my eyes. You can see them here for comparison:
<figcaption class="wp-caption-text">Cobalt2’s original iterm color theme</figcaption></figure>
I also want to make some tweaks to what info is conveyed on my status line like shortening up the current path a bit. If I roll my own theme or fork a good one that’s already out there I’ll add it to this article as a future update.
Thanks for following along and let me know if you have any questions or suggestions in the comments.