A lean terminal setup for doing more while typing less
By: Johannes Preis
Tags: Developer Tools, Terminal, Productivity, Command Line

We now have everything in place to start customizing our terminal setup. We’ll start by opening the aforementioned .zshrc file with our text editor of choice and tidying up a bit. A lot of lines were added during the installation of oh-my-zsh (mostly comments) — we’ll remove everything except for the required stuff:

I’ve added two custom aliases which will come in handy whenever we want to make adjustments to our zsh configuration. The first one zshcfg simply opens the .zshrc in our text editor of choice (I’m using Visual Studio Code which can also be launched from the command-line). The second one zshsrc is used for sourcing the .zshrc file so we don’t have to restart our terminal everytime we make changes. Manually source the file one more time using source ~/.zshrc and you are good to go!

Cosmetics

Before we explore and extend the functionality of our terminal setup, let’s first take some time to make it look nice and more functional at the same time. The two things we will be customizing are the prompt and the terminal window.

As mentioned in the beginning, we are going for a very lean and unobtrusive look. It’s not only about “aesthetics” though: It’s also about which information we actually need to be displayed in the terminal. The less “visual noise” there is, the easier it is to parse the information we’re actually interested in. For example, I don’t need to see my username and the name of the machine I’m logged on to in the prompt all the time — this might be different for your use cases but I encourage you to take this into consideration when building your own terminal setup.

Prompt

We’ve already seen some changes made to our prompt right after the installation of oh-my-zsh, which comes bundled with a large number of pre-defined prompt customizations called themes. Inside our .zshrc we can see that the default theme was applied with the following line:

ZSH_THEME="robbyrussel"

We can simply switch to a different predefined theme by inserting its name here. Just make sure to save your .zshrc file and source it afterwards (e.g. by using our custom zshsrc alias). I’m using the fox theme as an example here:

ZSH_THEME="fox"

oh-my-zsh using the ‘fox’ theme

If one of the themes that come bundled with oh-my-zsh suits your fancy, that’s all there is to do in terms of prompt customization.

However, if you prefer a bit more flexibility (and don’t want to manually create a theme, which can become quite intricate) I suggest you take a look at powerlevel10k (thanks to my colleague Christian Ivicevic for this recommendation!). It’s a zsh theme with a wide variety of customization options and great documentation. We will install it as a custom oh-my-zsh theme so it nicely integrates with our existing setup. First, clone the repository using the following command:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Afterwards, simply set powerlevel10k/powerlevel10k as the theme in your .zshrc . This time, you might have to restart your terminal for the changes to take effect. After restarting, you should be presented with the powerlevel10k configuration wizard. I recommend installing the Meslo Nerd font, as it contains all the glyphs required to properly display certain elements of the prompt. After installing the font, your iTerm 2 settings should be updated automatically to make use of it. Quit and restart your terminal one more time. Afterwards you should be taken back to the configuration wizard:

The configuration wizard only provides a baseline customization of the prompt — it can later be tweaked from within the .p10k.zsh file which will be created in your home directory after completing the wizard (you can always run it again by running p10k configure ). Im using the following options:

Prompt Style: Lean

Lean Character Set: Unicode

Unicode Prompt Colors: 8 colors (this way the prompt will only use the colors from current iTerm 2 color preset which makes for a more cohesive look)

8 colors (this way the prompt will only use the colors from current iTerm 2 color preset which makes for a more cohesive look) Show current time? No

No Prompt Height: One line

One line Prompt Spacing: Compact

Compact Icons: Few icons

Few icons Prompt Flow: Concise

Concise Enable Transient Prompt: No

No Instant Prompt Mode: Verbose (more info)

Verbose (more info) Apply changes to ~/.zshrc : Yes (this will update our .zshrc to load our configuration from the aforementioned .p10k.zsh file and also add the required lines to enable instant prompt mode)

After completing the wizard, our .zshrc should look something like this:

We should also immediately see the updated prompt:

As mentioned before, we can now further customize the prompt by editing the newly created .p10k.zsh file. It’s incredibly well documented which makes it very easy to adjust the prompt to our liking. For my configuration, I used a slightly different prompt symbol and moved the segments displaying the current directory and Git status to the right. I also disabled the segments displaying the exit code and the command execution time.

One more thing I recommend doing at this point is installing the zsh-syntax-highlighting plugin. As the name suggests this enables highlighting of commands while they’re typed into the terminal. With oh-my-zsh, the installation is quite simple. Clone the repository into your oh-my-zsh custom plugins directory using:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Afterwards, simply add zsh-syntax-highlighting to the (currently still empty) list of plugins in your .zshrc :

...

plugins=(zsh-syntax-highlighting)

...

After sourcing the file, you should see the syntax highlighting working once you start entering a command.

With our new prompt in place, we can now move on to the customization of the terminal window.

Terminal window

The first thing we will be doing here is to apply another color preset in iTerm. Again, there’s already a huge selection of color presets available. My current favorite is a port of Sarah Drasners Night Owl theme, which can be downloaded here. To apply a downloaded color preset, press Cmd + , to open the iTerm preferences. Go to “Profiles” and from within the “Colors” tab, select “Import…” from the “Color Presets…” dropdown and import the *.itermcolors file of your choice.

There are a few more settings I like to apply which make the overall appearance of the terminal window a bit cleaner:

Appearance

General

Theme: Minimal

Windows

Uncheck "Show window number in title bar"

Panes

Uncheck "Show per-pane title bar with split panes"

Dimming:

Check "Dimming affects only text, not background" Profile

Window

Check "Custom window title" and leave empty Advanced

General

- Height of top and bottom margins in terminal panes: 10

- Height of left and right margins in terminal panes: 20

With these settings applied, this is what our terminal should look like (note that I’ve also switched to a different font):

Nice! I really like this clean look which makes using the terminal much more enjoyable for me. It comes down to personal preference but with the setup presented here it is very easy to adjust it to your liking.

Now that our terminal looks great, it’s time to actually use it!

The terminal in action

In this section, we will explore common terminal workflows and how we can make them more efficient.

Invoking the terminal

Up until now, we had to manually bring our terminal to the front either by using the Dock or the macOS app switcher. But there’s a better way! iTerm 2 features a Hotkey Window which allows us to invoke the terminal using a global keyboard shortcut. To enable it, open the iTerm 2 preferences, go to “Profiles” and with your desired profile selected (we currently only use one), go to the “Keys” tab. Check “A hotkey opens a dedicated window with this profile”. I’m using the following settings here:

With these settings applied we can now always bring terminal to the front by pressing the respective shortcut (⌥ + Space in my case). This even works when using the terminal in fullscreen mode (which can be activated by pressing ⌘ + Enter). If you’re using multiple spaces, you should also set the “Space” setting to “All Spaces” within the “Window” tab. This way macOS won’t switch to another space when invoking the terminal and it will be displayed on your current space instead.

Split panes

Many tasks require the use of more than one terminal session. You might be running a dev-server for both a backend and a frontend and still want to use Git from the command line without killing the server first. That’s already four simultaneous terminal sessions! One way to solve this is to have multiple tabs in the terminal window (in iTerm 2, you can create a new tab by pressing ⌘ + T). However, I prefer using a different approach: Since I’m working on a large screen most of the time, there’s enough space to show all terminal sessions side by side using iTerm’s split pane feature: By pressing ⌘ + D or ⌘ + ⇧ + D you can create a new terminal session and split the current pane vertically or horizontally respectively. And if at some point you need more space for a specific pane you can maximize it by pressing ⌘ + ⇧ + Enter (press the same shortcut again to return to the side-by-side view).

There are two settings which make working with split panes more comfortable: Within the iTerm 2 preferences, in the “General” tab under “Profiles” set “Working Directory” to “Reuse previous session’s directory” to have the session in the new split pane start in your current working directory. Additionally in the “Navigation Shortcuts” tab under “Keys”, define a “Shortcut to choose a split pane” (I’m using ⌘ + Number) so you can easily switch the active pane.