Making your shell work and look great is not just for fun. You can easily turn your shell from a simple prompt into an interactive shell that will assist you and make your life a lot easier.
This guide will focus on ZSH but Bash can be partially customized as well although it's out of scope for this document.
A terminal application hosts your shell and lets it run. The terminal affects how you manage shells in tabs, windows, or panes. Mac OS comes with a very nice terminal app but iTerm2 is better in every single way with a lot of little quality of life enhancements with no downsides. And if you followed this guide it's already installed. Customizing iTerm2 is a pretty deep rabbit hole but feel free to experiment.
The default font is o.k. but in order to make you prompt shine you need a "nerd" font that contains a lot of additional emojis such as git statuses and the various frameworks.
There are many Nerd Fonts available but if you don't want to mess with it meslo
is a good choice and just run
brew tap homebrew/cask-fonts && brew install --cask font-meslo-lg-nerd-font
If you like a different font just replace meslo-lg
with you choice.
Open iterm2
and go to preference by pressing command+,
Navigate to profiles --> Text and choose the font you installed.
Starship will give your prompt super powers. By default it will show you what branch you're on, your commit status and what run times are used in the location (node, ruby, java, etc.). It will also show you how long each command took. If you're willing to work for it, there are many more customization options so feel free to dive in.
Because ZSH is so extensible Oh My ZSH will configuring it easier and work better. Just installing it will already make positive changes but in reality you definitely want to tweak it. Oh My ZSH is broken down into two big parts: themes
and plugins
which will be discussed below.
run the below and you're done.
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Themes make your terminal look like you want it to. The default is decent and non offensive.
If you want something flashier browse the themes
Note that these are just the included themes and there are many many more available but you'll have to google them.
to install a theme open ~/.zshrc
and find the
ZSH_THEME=robbyrussel
line. Replace the theme with the name you like and restart your terminal.
If you REALLY want to have the most powerful prompt ever and infinite customizability you should check out PowerLevel10K. If you go the Powerlevel10K route, do not install starship as they do the same thing. And be prepared to work a bit to get it to look like you want it to. Although the defaults are really great.
The plugins is where Oh My ZSH really shines. Plugins can add a ton of functionality and make using the shell a join.
Installing a Oh My ZSH plugin is usually a two step process
- Clone the plugin repository into the oh my zsh plugin folder
- enable the plugin in the
~/.zshrc
file.
ZSH has to load all of the plugins you chose and they all react to everything so you really don't want to go overboard. In general, ZSH can handle 10's of plugins with no performance issues but if it feels slow disable some plugins and see which one is killing you.
The only built-in plugin in My Oh ZSH is git
and it's hard to give general recommendations. However, there are two plugins that will propel ZSH to the next level.
- zsh-autosuggestions - will offer completion of common commands and commands from your history which means you'll eventually just type the beginning of common commands.
- zsh-syntax-highlighting - Will highlight the commands. Specifically commands will turn green if they're valid and red if they're not making it easy to know you got it right.
Installing these two extensions (and optionally the fishy
theme) will give you an almost identical experience to the fish shell.
Clone the two plugins:
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
Open ~/.zshrc
and find plugins=(git)
and replace with plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
The parentheses are a weird Bash array syntax. Just make sure the plugins are separated by a space and are enclosed in parentheses with no leading or trailing spaces.
The plugin ecosystem is vast. Most are specific for your workload such as docker
ruby
rails
node
python
etc. and will provide you with awesome autocomplete powers.
Others are more generic and here are some that can be useful:
- Z - Will continuously track what folders you go into and will quickly be smart enough to take you there so you could replace
cd my/very/long/and/annoying/path/
toz path
. - The Fuck - This is bit more complex but it will let you just type
fuck
when you made a stupid spelling mistake and have the command be corrected automatically! Pure magic! and you can alias the command if it's hard on your pure soul. The Oh My ZSH plugin will let you pressESC
twice to save even more time.
Aliases are shortcuts to commands. Defining an alias is really simple - the command is alias
and you give it a name and the command with an =
sign in between for example:
alias gitp='git pull'
will run git pull
every time you type gitp
. But you're not limited to a single command for example
alias buildproj='cd ~/proj && npm build
will cd to the project and build it in a single command.
An alias is only valid for the current session. To make your aliases always available add the command as it is in a new line at the end of your ~/.zshrc
line.
Shell multiplexing is running a lot of shells together. There are four ways to multiplex:
- window - Just open new windows of your terminal.
- tabs - the default in
terminal
anditerm
will open a new tab for each shell - panes -
iterm
allows you to open "panes" which are sub windows that allow you to track multiple running commands at once. - shell multiplexing - the likes of tmux which will let you run multiplexing within the shell.
The most advanced form of multiplexing which has a stiff learning curve but highest productivity. Another advantage of
tmux
is that it can ran everywhere including over ssh. But it's not for the faint of heart.
itermocil let's you predefine your multiplex and get back to it with no work. It will let you predefine pane location, size and even run a command on opening the pane. itermocil
requires iterm2
.
tmux will do that and more but requires more effort.