Yet another step-by-step guide for a better terminal setup
I use iTerm2 + zsh + Prezto + starship.rs and so should you!
Benefits in a nutshell
- it looks cooler
- better file globbing, spelling correction, a self-learning cd command and tons of plugins
- useful information about git, your virtual environment, the k8s context and more
See for yourself!
To get the same terminal awesomeness, here are step-by-step instructions to get you there.
Disclaimer: These step-by-step instructions only work for OS X. Everything but iTerm2 should also run on Linux though.
iTerm2 + color scheme + font
Download and install iTerm2 here.
Next we’ll install the Solarized Dark color scheme. Download this file and make sure it has the .itermcolors extension.
- Launch iTerm 2.
- Type CMD+i (⌘+i)
- Navigate to Colors tab
- Click on Color Presets
- Click on Import
- Select the .itermcolors file
- Click on Color Presets and choose a color scheme
If you want a different color scheme, you can find more here. For inspiration what might look cool with the spaceship-prompt look here.
We also need to download and install a Font with Powerline support to make sure we can see the pretty symbols used by the spaceship-prompt (otherwise we’ll just see question marks). I use Fira Code: a beautiful font that contains ligatures that combine certain characters into one for better readability. Launch iTerm and copy and paste the following to install the fonts.
brew tap homebrew/cask-fonts
brew install --cask font-fira-code
To tell iTerm to use it, do
- Launch iTerm 2.
- Type CMD+i (⌘+i)
- Navigate to Text tab
- Click on Change Font
- Select Fira Code
zsh + Prezto + spaceship-prompt
Now to the interesting stuff. Launch iTerm and check which shell you have installed. You can do this by running
echo $0
Newer Mac OS X versions come with zsh as the default shell. If you see anything else than zsh, you can install and launch it by running
brew install zsh # to install
zsh # to launch
Next we’ll install Prezto. Here is their GitHub explanation:
Prezto is the configuration framework for Zsh; it enriches the command line interface environment with sane defaults, aliases, functions, auto completion, and prompt themes.
In other words it is our plugin manager and will allow us to quickly experience some zsh awesomeness.
First, clone the repository.
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
Make sure you have no existing ~/.zshrc otherwise the setup will not work (it will complain about an existing file). To set up all the necessary configuration files run
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
The two files you need to care about are ~/.zshrc and ~/.zpreztorc.
~/.zshrc is your general shell configuration file.
~/.zpreztorc is where you manage your Prezto plugins.
Next open your ~/.zpreztorc file with your favorite text editor. And navigate to the modules section. See below, what mine looks like this. Feel free to copy and paste it, but make sure to have a look at the different modules you can add here.
# Set the Prezto modules to load (browse modules).
# The order matters.
zstyle ':prezto:load' pmodule \
'environment' \
'terminal' \
'editor' \
'history' \
'directory' \
'spectrum' \
'utility' \
'completion' \
'osx' \
'ssh' \
'python' \
'git' \
'syntax-highlighting' \
'history-substring-search' \
'prompt'
Save the ~/.zpreztorc file. And run the following line to set the zsh as your default shell.
chsh -s /bin/zsh
Next, let’s install jump. It adds the awesome j command, which is basically cd on steroids (it remembers which directories you navigate to a lot and after while you can just type j some-directory-name to go straight to that directory without navigating through the directory structure of your Mac one by one).
Run
brew install jump
and then add the following to the end of your ~/.zshrc
eval "$(jump shell)"
The other command I use a lot is Ctrl-r: it starts a substring search in your command history and is very convenient to find long commands you used in the past and need to use again. Make sure you also install fzf to get Ctrl-r on steroids (see below).
Next, let’s add starship.rs to make our prompt look beautiful. Install it with
brew install starship
and then add the following to the end of your ~/.zshrc
eval "$(starship init zsh)"
Hit CMD + i and click on “General”. Press “Copy Current Settings to Selected Profile” to save all the settings. Lastly, close iTerm and re-start it for the changes to have effect and get ready to enjoy some zsh-awesomeness.
More command line bliss
fzf — A command-line fuzzy finder
Makes the command-backward-search (with Ctrl-r) even more beautiful and also comes with awesome built-in support for things like kill -9 (no more messing with pids, just hit TAB and do a fuzzy search for the process name you want to kill). Using it is pure bliss.
To install just do:
brew install fzf
# To install useful key bindings and fuzzy completion:
$(brew --prefix)/opt/fzf/install
tldr — simplified and community-driven man pages
No more messing with ugly man pages. just do `tldr zip` instead of `man zip` and get a beautiful summary of the most common ways to use the given command.
To install just do:
brew install tldr
rg — ripgrep recursively searches directories for regex patterns
A better version of grep.
brew install ripgrep
bat — A cat(1) clone with wings
A better version of cat.
brew install bat
exa— A modern replacement for ls
A better version of ls.
brew install exa
Change Log
- August 5th, 2022: Changed the font from Meslo LG Powerline to Fira Code. Changed fasd to jump. Changed spaceship-prompt to starship.rs.