Crafting A Productivity Environment With Iterm Tmux And Beyond 1

# Terminal Mastery: Crafting a Productivity Environment with iTerm, tmux, and Beyond

Table of Contents

I love working on Linux terminals

Rewind a decade or so, and you’d find me ensconced within the embrace of a Linux terminal for the duration of my day. Here, amidst the digital ebb and flow, I thrived—maneuvering files and folders with finesse, weaving code in Vim, orchestrating services maintenance, decoding kernel dumps, and seamlessly transitioning across a mosaic of tmux sessions.

The graphical user interface? A distant thought, unnecessary for the tapestry of tasks at hand.

Like all geeks, every tech enthusiast harbors a unique sanctuary of productivity—a bespoke digital workshop where code flows like poetry, and ideas ignite with the spark of creativity. It’s a realm where custom tools and secret utilities interlace, forming the backbone of unparalleled efficiency and innovation.

Today, I’m pulling back the curtain to reveal the intricacies of my personal setup on Mac.

I invite you on this meticulous journey through the configuration of my Mac-based development sanctuary.

Together, let’s traverse this path, transforming the mundane into the magnificent, one command, one tool, one revelation at a time.

iTerm2

After account setup on Mac, the initial terminal looks like this when I logged in:

Default macOS Terminal window right after logging in, plain white background with a basic prompt Animated meme of a bored kid, reacting to the plain default terminal

Let’s equip it with iTerm2!

iTerm2 logo with the tagline: a terminal emulator for macOS that does amazing things
What is iTerm2?

iTerm2 is a replacement for Terminal and the successor to iTerm. It works on Macs with macOS 10.14 or newer. iTerm2 brings the terminal into the modern age with features you never knew you always wanted.

Why Do I Want It?

Check out the impressive features and screenshots. If you spend a lot of time in a terminal, then you’ll appreciate all the little things that add up to a lot. It is free software and you can find the source code on Github.

How Do I Use It?

Try the FAQ or the documentation. Got problems or ideas? Report them in the bug tracker, take it to the forum, or send me email (gnachman at gmail dot com).

Go ahead to https://iterm2.com/ download it and finish installation. Open it:

Freshly installed iTerm2 window with its default black theme and prompt

Well, still not impressive. But, now you have got all advanced features from iTerm!

This blog post is not focus on iTerm2, we can discuss later. So I am not going through those fancy features right now, please explore on the official website.

Let’s start to customize on it.

Wait, Nerd … Font

Before we jump on the customization on iTerm2, I want to introduce you Nerd Font.

It will be required and installed by https://github.com/romkatv/powerlevel10k which we will talk later.

Nerd Fonts GitHub project page header with the patched font icons

This project aims to enhance the usability and aesthetic appeal of the development environment without sacrificing the functionality or readability of the text. The added icons can represent common actions or tools in the development workflow, allowing for a more intuitive and visually engaging interface.

By incorporating icons directly into the fonts, Nerd Fonts allows developers to use these icons across different applications and tools seamlessly, without needing to rely on external libraries or tool-specific extensions. This can simplify setup and configuration across tools and platforms, providing a consistent and enriched visual experience.

Customize iTerm2

Just follow me:

iTerm2 Preferences General Selection tab with clipboard access and smart selection options highlighted iTerm2 Profiles Text settings with underline cursor, Powerline glyphs and MesloLGM Nerd Font Mono selected

Set your favorite character as background image if you like:

iTerm2 window with a favorite character image set as the terminal background

Let’s compare previous and now:

Default macOS Terminal window right after logging in, plain white background with a basic prompt
iTerm2 window after customization, showing the new background image and styled prompt

Oh-my-zsh and powerlevel10k

Install https://github.com/ohmyzsh/ohmyzsh (to manage zsh):

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Terminal output of the Oh My Zsh installer finishing successfully

Install https://github.com/romkatv/powerlevel10k for ohmyzsh and configure it (powerlevel10k is a theme of zsh).

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

Set environment:

echo "source ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme" >> ~/.zshrc

Restart Zsh with exec zsh.

You should see:

Powerlevel10k configuration wizard first screen asking whether the prompt icons render correctly

Let’s install the fonts and follow the wizard, choose whatever you like!

Now it looks much better!

iTerm2 with Powerlevel10k applied: a Powerline prompt showing the current folder and git branch, with a cartoon character as background

Much better, but still not meet my expectation!

Let’s begin working with our adaptable TMUX expert now!

tmux wiki page on GitHub introducing the terminal multiplexer

tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

Tmux should have been installed by default, type tmux, you should see:

Default tmux session with a plain green status bar at the bottom of the terminal Animated meme of a bored kid, reacting to the plain default terminal

Can’t wait to customize it!

I am using https://github.com/gpakosz/.tmux.git:

It’s a Self-contained, pretty and versatile .tmux.conf configuration file.

cd ~
rm -fr .tmux
git clone https://github.com/gpakosz/.tmux.git
ln -s -f .tmux/.tmux.conf
cp .tmux/.tmux.conf.local .

Append below into .tmux.conf.local before the line “# -- custom variables”:

# increase history size
set -g history-limit 9999999
# start with mouse mode enabled
set -g mouse on
bind-key -n C-S-Left swap-window -t -1\; select-window -t -1
bind-key -n C-S-Right swap-window -t +1\; select-window -t +1
# -- custom variables ----------------------------------------------------------

I am a fan of Vi/Vim, must enable Vi mode in “~/.tmux.conf.local”:

Lines in .tmux.conf.local that enable Vi mode key bindings

Customize status bar:

tmux_conf_theme_status_right_fg="$tmux_conf_theme_colour_12,$tmux_conf_theme_colour_14,$tmux_conf_theme_colour_6"
tmux_conf_theme_status_right_bg="$tmux_conf_theme_colour_15,$tmux_conf_theme_colour_17,$tmux_conf_theme_colour_9"
tmux status bar color settings in .tmux.conf.local using theme colour variables
tmux_conf_theme_left_separator_main='\uE0B0'
tmux_conf_theme_left_separator_sub='\uE0B1'
tmux_conf_theme_right_separator_main='\uE0B2'
tmux_conf_theme_right_separator_sub='\uE0B3'
tmux separator settings in .tmux.conf.local using Powerline glyph codes

Find below lines in “~/.tmux.conf.local” and uncomment them to enable:

tmux plugin lines for tmux-resurrect and tmux-continuum with restore turned on

Set a icon for the left status:

tmux configuration line that sets an icon for the left side of the status bar

Now reload configuration:

tmux source ~/.tmux.conf

Check it now!

Customized tmux session in iTerm2 with a Powerline-style status bar and the Powerlevel10k prompt

I have a script to launch Tmux when starting iTerm2, here you go:

#!/bin/zsh
tmux ls|grep kongfu | grep -q attached
if [[ $? != 0 ]] ; then
tmux attach -t kongfu || tmux new-session -s kongfu
else
echo "********************************************************************************"
echo "* Ignore attaching tmux kongfu session as it has been attached already. *"
echo "********************************************************************************"
fi

Save it “~/bin/tmux_init.sh” and “chmod 755 ~/bin/tmux_init.sh”, configure it in iTerm2 default profile:

iTerm2 Default profile General tab with ~/bin/tmux_init.sh set as the Send text at start command

Customize P10K Status Bar for Anaconda and Node.js

I have Anaconda and Node.js environments.

I am not satisfied with the default color settings for Anaconda and node.js. It’s ugly.

Open your ~/.p10k.zsh, make below changes:

Powerlevel10k config lines setting the Anaconda segment foreground to 0 and background to orange1 Powerlevel10k config lines setting the Node.js version segment foreground to 7 and background to green4 Powerlevel10k right prompt elements list in .p10k.zsh with the node_version entry highlighted

Now resource the file:

source ~/.p10k.zsh

Show time!

I recorded this to show you how it looks like on my environment:

https://www.youtube.com/watch?v=TBfvoSeyP4U

My avatar

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.


More Posts