macOS awesome terminal
Tags: tutorial, productivity, macos, terminal
Published: 2022-01-28 16:20:14

Hello **developers** 🧑‍💻, **thanks** for reading my post 🙏.

**A shell** is a user interface for **access to an operating system’s services**. Most often the user interacts with the shell using a command-line interface (CLI). The **terminal** 💻 is a program that opens a graphical window and lets you **interact with the shell**.

As developers, one of the **programs we use most** is our terminal, and as such it should allow us to **be as productive and fast as possible** 🚀 as well as to show off its features and pretty look 😎.

So let's embark on a journey 🧭 to make our **terminal in macOS no less awesome** 🙌.

---

### iTerm2

![iTerm2 logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k72iwffq3nzw3phlp6ay.png)

Initially, we will **replace** the **preinstalled terminal** for [**iTerm2**](https://iterm2.com/index.html), which has [tons of very useful features](https://iterm2.com/features.html).

- Go to [iTerm2 download page](https://www.iterm2.com/downloads.html) and downloaded the stable release.
- After the download is complete, drag the file to the Applications folder.
- Bonus: Place iTerm2 in a convenient place in the dock (replace the original terminal if you already have it there).

> iTerm2 **has a standalone update mechanism** so I prefer to **install it manually** rather than through a brew cask.


### Oh My Zsh

![Oh My Zsh logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3q5qbh319pp5smupvgi.png) 

Next, let's **unleash our terminal** by [installing **Oh My Zsh**](https://github.com/ohmyzsh/ohmyzsh/wiki).

> [Oh My Zsh](https://ohmyz.sh/) is an open source, community-driven framework for managing your Zsh configuration.

Oh My Zsh **comes bundled** with [**plugins**](https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins) that'll make your life as a developer easier and leave you **feeling like a superhero**.

To enable a plugin add its name to the plugins array in your `.zshrc` file (found in the `$HOME` directory).
Here are some that **I highly recommend**:
```zsh
plugins=(alias-finder brew common-aliases copypath copyfile docker encode64 git history jsontools macos web-search z)
```

---

> When **installing** Zsh's [theme](#zsh-theme) and [plugins](#zsh-plugins), opt for [**oh-my-zsh installation**](https://github.com/romkatv/powerlevel10k#oh-my-zsh) (... which is actually a `git clone` of the plugin's repo into the `$ZSH_CUSTOM` folder and a setting change in `.zshrc`). It will play best with the other settings in `.zshrc`, and the **autoupdate plugin** will keep them **up-to-date**.


### Zsh Theme <a name="zsh-theme"></a>

**My choice of theme** for Zsh is [**Powerlevel10k**](https://github.com/romkatv/powerlevel10k). Beyond being fast and minimal, it has **maintained its popularity** for many years and **continues to improve** with each new version. Also, I'm totally in favor of **installing** the [**recommended font**](https://github.com/romkatv/powerlevel10k#fonts) that comes with it.

### Zsh plugins <a name="zsh-plugins"></a>

- [**autoupdate-zsh-plugin**](https://github.com/TamCore/autoupdate-oh-my-zsh-plugins): Auto update git-repositories in $ZSH_CUSTOM folder. This plugin **is crucial** because it **keeps the rest** of the plugins **up-to-date**.
- [**zsh-syntax-highlighting**](https://github.com/zsh-users/zsh-syntax-highlighting): It enables highlighting of commands while they’re typed. This helps in reviewing commands before running them, particularly in catching syntax errors.
- [**zsh-autosuggestions**](https://github.com/zsh-users/zsh-autosuggestions): It suggests commands as you type based on your history and completions.
- [**zsh-history-substring-search**](https://github.com/zsh-users/zsh-history-substring-search): Type in any part of any command from your history, and then press chosen keys, such as the UP and DOWN arrows, to cycle through matches.
- [**zsh-nvm**](https://github.com/lukechilds/zsh-nvm): Zsh plugin for installing, updating and loading nvm. [nvm](https://github.com/nvm-sh/nvm) installation is relevant for developers working with [node.js](https://nodejs.org/). This plugin is recommended since [nvm via brew isn't supported](https://github.com/nvm-sh/nvm#important-notes).

---

### iTerm2 Elevation

> To **open the preferences** at any stage, Open iTerm2 → Press `(command) ⌘ + , (comma)`.

#### Shell Integration

Enabling the shell integration feature **enables many useful features** by itself.
[Follow the **official documentation** instructions](https://iterm2.com/documentation-shell-integration.html).
In practice the steps should look something like this: ![install-shell-integration-1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy08ggzb5z8jmdg71lzm.png) ![install-shell-integration-2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uygkloi4ihkonxa28no7.png)

#### Key Mappings

Setting these [**key mappings**](https://iterm2.com/documentation-preferences-profiles-keys.html) allows us to **use common keyboard shortcuts** in our terminal.

[Follow the **instructions in the gist**](https://gist.github.com/rannn505/0496cf92e65c69c12a8e38181dd98e6d?permalink_comment_id=4043484#gistcomment-4043484) I made for this purpose, and if you found it helpful, I'd appreciate you giving it a star as well.

#### Hotkey

Setting a [**hotkey**](https://iterm2.com/documentation-hotkey.html) allows us to **show or hide iterm window** even if another application is active.

- Preferences → Keys → Hotkey → ☑️ Show/hide all windows with a system-wide hotkey 
- Click on the rectangle that appears right to "Hotkey:" → Set your preferred key sequence
![hotkey-setting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ymqxucctes24vmn9z55e.png)

#### Status Bar

Setting up the [**status bar**](https://iterm2.com/documentation-status-bar.html) allows us to **get up-to-date information** about the environment we're working in.

- Preferences → Profiles → Session → ☑️ Status bar enabled
- Click Configure Status Bar button to begin setting up your status bar configuration.
My active components are: CPU Utilization, Memory Utilization and Network Throughput
![my-status-bar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hrcoo7nlg5zsn75f80n.png)

#### Remove the `last login: ...` line on top of each new window

```zsh
cd ~; touch .hushlogin
```

#### Allow iTerm to access administrative files

- System Preferences → Security & Privacy → Full Disk Access → ☑️ iTerm.app

#### Use TouchID for sudo execution

- Open `/etc/pam.d/sudo` with a text editor as admin
```zsh
sudo vim /etc/pam.d/sudo
```
- add `auth sufficient pam_tid.so` line **on top** and save
![/etc/pam.d/sudo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hsvty9vhr0gbsxcylj9r.png)
- Preferences → Advanced → Allow sessions to survive logging out and back → Select "No"

#### Set some "nice to have" preferences

- General → Closing → ☑️ Quit when all windows are closed
- General → Selection → ☑️ Double-click performs smart selection
- General → Window → ☑️ Smart window placement
- Appearance → General → Theme → Select "Minimal"
- Appearance → Tabs → ☑️ Show tab bar even when there is only one tab
- Profiles → General → Icon (Basics) → Select "Built-in Icon for Current App"
- Profiles → General → Working Directory → 🔘 Advanced Configuration → Edit... → Working Directory for New Split Panes → 🔘 Reuse previous session's directory
- Profiles → Text → Cursor → 🔘 Vertical bar + ☑️ Blinking cursor
- Profiles → Text → Font → Increase size (I use `16` as in my IDE)
- Profiles → Terminal → Shell Integration → ☐ Show mark indicators
- Keys → Navigation Shortcuts → Shortcut to choose a split pane → Select your preferred option (I use `⌥ Number`)
- Pointer → General → ☑️ Focus follows mouse
- Advanced → Mouse → Scroll wheel sends arrow keys when in alternate screen mode → Select "Yes"

#### Add a screensaver

- [CMatrix](https://github.com/abishekvashok/cmatrix) shows text flying in and out in a terminal like as seen in "The Matrix" movie.
```zsh
brew install cmatrix
cmatrix
```
- [pipes.sh](https://github.com/pipeseroni/pipes.sh) shows animated pipes.
```zsh
brew install pipes-sh
pipes-sh
```

#### Install useful command-line tools

{% github agarrharr/awesome-cli-apps no-readme %}
{% link https://dev.to/rannn505/macos-developer-n4n#cli-tools %} 

---

### The Result ✨

[**configuration files (.zshrc, iterm-profile.json etc..) as a gist**](https://gist.github.com/rannn505/b02ad6e465d02b155646f2b1eb88ae72)

![result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25cogqf592kj2yo802ir.png)