iTerm2 is an open source replacement for Apple's Terminal. It's highly customizable and comes with a lot of useful features.
You can get the app from iTerm2 downloads page. Once downloaded, drag and drop the iTermapplication file into your Applications folder.
{% hint style="info" %}
Instead of downloading and installing iTerm2 manually, you can use Homebrew
brew cask install iterm2
{% endhint %}
We are going to setup spaceship-prompt
The final setup will be like this:
For correct work you will first need:
zsh
(v5.0.6 or recent) must be installed.- Powerline Font must be installed and used in your terminal.
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.
The configuration file for zsh
is called .zshrc
and lives in your home folder (~/.zshrc
).
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
:
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:
chsh -s $(which zsh)
{% hint style="info" %} Only for Linux:
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:
command -v zsh | sudo tee -a /etc/shells
Then we can set zsh as default shell with:
sudo chsh -s "$(command -v zsh)" "${USER}"
{% endhint %}
The out-of-the-box configuration is usable but you probably want to customise it to suit your needs. The Official 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:
source ~/.zshrc
Add plugins to your shell by adding the name of the plugin to the plugin
array in your .zshrc
.
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. Note that adding plugins can cause your shell startup time to increase.
To use spaceship
we need to setup Powerline Fonts
. To do it open a new terminal and exec the following commands:
# 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/
In Preferences > Profiles > Text and select the fonts:
{% 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 %}
In the terminal run:
# 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:
You can find the official spaceshipt-prompt documentation on Gitbook here: https://denysdovhan.com/spaceship-prompt/