paint-brush
How to Customize your Terminal with ZSHby@sambernheim
98,714 reads
98,714 reads

How to Customize your Terminal with ZSH

by Sam BernheimAugust 28th, 2018
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

When I first began using my terminal it looked like this

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How to Customize your Terminal with ZSH
Sam Bernheim HackerNoon profile picture

When I first began using my terminal it looked like this

Basic Terminal

And now, it looks LIKE THIS:

Tricked out Terminal

So how do you get from one to the other, well for me it took about 2 years to learn enough but lets see if we can’t help speed that up for YOU!

😎

Step 1: Ditch Bash and Use ZSH + Oh-My-ZSH

First, some terminalogy — bwhahaha get it TERMINALogy!! *wipes tear from eye* 😂

Ok, maybe thats it for the terrible puns

So you have your terminal application. This is the default terminal app on mac/linux/windows or iTerm2 or powershell etc. (You should definitely be using iTerm2 though).

Then you have the shell which is the thing running in the application. There are a bunch of these

  • Bash (stands for Bourne Again Shell)
  • ZSH (Z-Shell)
  • C-Shell
  • Fish
  • etc etc

They all work a little differently or support different features. ZSH is super easy to customize though which is why we’ll be using it. If you have a mac you can brew install zsh or for linux sudo apt-get install zsh if neither work/for more info check here for more methods to install.

Now all you need to do is set it as your default shell with this command chsh -s zsh. chsh stands for, you guessed it change shell, -s tells the command that you want to change it to a specific shell which you pass in as an argument which here is zsh. You’ll be asked for your computer password too.

Step 2: Install Oh-My-ZSH

Install instructions here: https://github.com/robbyrussell/oh-my-zsh#via-curl

Congrats, Two steps done!! See how easy this is.

Step 3: Getting the Right Fonts

You’ll want to check out this repo: https://github.com/ryanoasis/nerd-fonts#font-installation which contains a ton of fonts which support all the awesome, cool symbols you’ll want to use. Its a lot of fonts to install so be sure you don’t run this while your connectivity might drop or if you’re in a rush.

Nerdfont fonts support font-awesome glyphs, material design icons, octicons and more.

Nerdfont source fonts diagram

If you just want to get one, this is the font I’m using and its worked great. Just click the link, download the ttf file and install the font to your computer. If you see the box with a question mark in it a times, it means the font you are using in your terminal doesn’t support that character.

Unsupported character symbol

Step 4: Themes and Colors

You have two things to focus on when customizing your terminal. The first is the theme. This is the way the terminal is going to look. The second is the colors of those things. This determines what shade of blue is your blue, what red is your red etc.

First lets talk themes. To get started take a look at https://github.com/robbyrussell/oh-my-zsh/wiki/themes

All of these are baked into oh-my-zsh and all you have to do is edit your .zshrc file (its located at ~/.zshrc) and set ZSH_THEME="THEME_NAME", so ZSH_THEME="agnoster" for example, and thats it.

Example of iTerm2 Color Scheme called Broadcast

As for colors, you can take a look at this repo which has a bunch of nice color schemes ready to download for iTerm2. The colors can be edited in the settings. Go to settings > profiles > colors. In the bottom right corner is the color presets list. Click this and you’ll see an option to import a color scheme or select some built in ones. Import any of the color schemes you download from that repo.

Step 5: Powerlevel 9K

Another awesome repo I recently found is PowerLevel 9K. It serves the same purpose as the themes in oh-my-zsh.

To install PowerLevel 9k check here for instructions

And then check out this page to see all the cool stuff other people have built. Find one you like and copy their settings into your .zshrc file and then you can modify bits and pieces until its just how you like. I’d do this first before you try and build your own from scratch. Your mileage may vary with some of them. But once you find one you like you can modify any of the variables until its just how you like it.

(Some of the configs might include POWERLEVEL9K_MODE="SOMETHING_HERE" and ZSH_THEME="powerlevel9k/powerlevel9k". If you already have them in your .zshrc delete the duplicate and if you’re setting the first option make sure its set before ZSH_THEME is.)

Step 6: Writing Your Own Functions

Powerlevel 9K supports a lot out of the box including github status/other version control systems, current working directory, host, node version, time/date, and tons more.

You can also write your own functions to display more stuff. Below is the function I have to show if I’m connected to the internet. If so I display the symbol in green. Otherwise in red. You can write any bash function and have it echo a statement at the end . Then to include it in the prompt add custom_internet_signal (or whatever your function is called) and whatever the function echo’s will appear!

Note: this function is stored in .zshrc.

Note 2: \uXXXX is saying display this unicode character. To actually know what character that is google u+XXXX unicode character.

You can write functions to show your battery level (different icons for different statuses, different colors for different levels etc). The song playing on Spotify etc (this might take some work but check out https://github.com/hnarayanan/shpotify or https://github.com/johnelse/spotify-cli), Docker status etc.

And thats it! 6 steps to trick out your terminal!

As always if you want to take a look at my dotfiles for reference here it is. Feel free to fork or clone it (I wouldn’t use the install script though to replicate everything, its fairly buggy and is not up to date).