> For the complete documentation index, see [llms.txt](https://daton.gitbook.io/daton-mac/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://daton.gitbook.io/daton-mac/iterm2.md).

# iTerm2

[iTerm2](http://www.iterm2.com/) is an open source replacement for Apple's Terminal. It's highly customizable and comes with a lot of useful features.

## Installation

You can get the app from [iTerm2 downloads page](http://www.iterm2.com/downloads.html). Once downloaded, drag and drop the **iTerm**application file into your **Applications** folder.

{% hint style="info" %}
Instead of downloading and installing iTerm2 manually, you can use `Homebrew` `brew cask install iterm2`
{% endhint %}

## Customization

We are going to setup [spaceship-prompt](https://github.com/denysdovhan/spaceship-prompt)

The final setup will be like this:

![Image from spaceship-prompt](https://3595171846-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD7__2zPv5tlcGFmbZU%2F-LDRn6hwvf34QZRLRCS1%2F-LDRnQSOfJ4SSFM39sLe%2F36086434-5de52ace-0ff2-11e8-8299-c67f9ab4e9bd.gif?alt=media\&token=f745d019-c169-4840-ada4-d87f32483bbd)

###

### Requirements

For correct work you will first need:

* [`zsh`](http://www.zsh.org/) (v5.0.6 or recent) must be installed.
* [Powerline Font](https://github.com/powerline/fonts) must be installed and used in your terminal.

### Install zsh

The Z shell (also known as `zsh`) is a Unix shell that is built on top of `bash` (the default shell for macOS) with additional features. It's recommended to use `zsh` over `bash`. It's also highly recommended to install a framework with `zsh` as it makes dealing with configuration, plugins and themes a lot nicer.

We've also included an `env.sh` file where we store our aliases, exports, path changes etc. We put this in a separate file to not pollute our main configuration file too much. This file is found in the bottom of this page.

Install `zsh` using Homebrew:

```
$ brew install zsh
```

Now you should install a framework, we'll use [Oh My Zsh](https://github.com/robbyrussell/oh-my-zsh).

The configuration file for `zsh` is called `.zshrc` and lives in your home folder (`~/.zshrc`).

### Oh My Zsh <a href="#oh-my-zsh" id="oh-my-zsh"></a>

[Oh My Zsh](https://github.com/robbyrussell/oh-my-zsh) is an open source, community-driven framework for managing your `zsh` configuration. It comes with a bunch of features out of the box and improves your terminal experience.

Install `Oh My Zsh`:

```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
```

The installation script should set `zsh` to your default shell, but if it doesn't you can do it manually:

```bash
chsh -s $(which zsh)
```

{% hint style="info" %}
Only for Linux:&#x20;

We can get an error: *chsh: /home/linuxbrew/.linuxbrew/bin/zsh is an invalid shell*

To fix this error we need to add zsh in the list of the available shells in the system, so run:&#x20;

```bash
command -v zsh | sudo tee -a /etc/shells
```

Then we can set zsh as default shell with:&#x20;

```bash
sudo chsh -s "$(command -v zsh)" "${USER}"
```

{% endhint %}

#### Configuration

The out-of-the-box configuration is usable but you probably want to customise it to suit your needs. The [Official Wiki](https://github.com/robbyrussell/oh-my-zsh/wiki) contains a lot of useful information if you want to deep dive into what you can do with Oh My Zsh, but we'll cover the basics here.

To apply the changes you make you need to either **start new shell instance** or run:

```bash
source ~/.zshrc
```

#### **Plugins**

Add plugins to your shell by adding the name of the plugin to the `plugin` array in your `.zshrc`.

```bash
plugins=(git colored-man-pages colorize brew osx zsh-syntax-highlighting)
```

You'll find a list of all plugins on the [Oh My Zsh Wiki](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins). Note that adding plugins can cause your shell startup time to increase.

### Font Setup

To use `spaceship`we need to setup `Powerline Fonts`. To do it open a new terminal and exec the following commands:

```bash
# clone poweline fonts repo
git clone https://github.com/powerline/fonts.git --depth=1
# install it 
cd fonts/
./install.sh
# clean-up a bit
cd ..
rm -rf fonts/
```

#### Setting fonts in iTerm2

&#x20;In Preferences > Profiles > Text and select the fonts:

![](https://3595171846-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD7__2zPv5tlcGFmbZU%2F-LDWH30DQXpk6GVzk_Tq%2F-LDWHiLLOsOOiw2Qd50q%2Fiterm%20fonts%20prefs.png?alt=media\&token=fa388f70-47f5-498d-9269-6c948b47e869)

{% hint style="info" %}
Installing a patched font will mess up the integrated terminal in `Visual Studio Code` unless you use the proper settings. You'll need to go to settings (`CMD + ,`) and add or edit the following values:

* for Source Code Pro: `"terminal.integrated.fontFamily": "Source Code Pro for Powerline"`
* for Meslo: `"terminal.integrated.fontFamily": "Meslo LG M for Powerline"`
* for other fonts you'll need to check the font name in Font Book.

You can also set the font size e.g.: `"terminal.integrated.fontSize": 14`
{% endhint %}

![](https://3595171846-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD7__2zPv5tlcGFmbZU%2F-LDWH30DQXpk6GVzk_Tq%2F-LDWIWVWrvXgiSSm2xDR%2FScreen%20Shot%202018-05-27%20at%2013.13.39.png?alt=media\&token=f84873ce-1a4b-442a-be5c-2caf19ba2daa)

### We can finally install Spaceship&#x20;

In the terminal run:

```bash
# clone spaceship repo in the themes folder of zsh
git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt"
# link the folder 
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"
```

Now open \~/.zshrc and replace ZSH\_THEME="robbyrussell" with ZSH\_THEME="spaceship"

Restart iTerm2 and at this point you should have a result like this:&#x20;

![](https://3595171846-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD7__2zPv5tlcGFmbZU%2F-LDRuQOxF3uHlzzH-_Ro%2F-LDRuTRhuiNJysPfywLq%2F2018-05-26%2016.43.48.gif?alt=media\&token=ff4a9fd9-2976-4ed7-b5fb-abb72f156194)

You can find the official spaceshipt-prompt documentation on  Gitbook here: <https://denysdovhan.com/spaceship-prompt/>
