Terminal: Zsh and forget

42ohaan
rabbitsync
Published in
6 min readApr 21, 2019

Welcome a new command line experience.

Bit of a primer You can do without all this. This document is not supposed to show you can do it fast. This document is supposed to make you want to do it, even if it took you years as with me. Roaming the internet, looking for parts. Because what you get in return is basically Batman’s belt.

Batman doesn’t need it. But Batman get’s it.

But what do I get?

Fig 1. Terminal that doesn’t come default with most Macs

What you get are looks. No, seriously. Who cares about excellent blogging, Notice in Fig 1:

  1. Git integration.
  2. Your commands will turn red on the fly when they’re not spelt right. They’ll stay green, and offer you to auto-complete them if they’re spelt right.
  3. That Apple icon below “Password”? Turns into a dolphin so you can tell that the machine you just ssh-ed into is Linux.
  4. The terminal can autocomplete your commands so you won’t have to.
  5. It can show if you are you; it can show if you gone root. Side lock unlocks when you do that.
  6. When you select anything in the terminal, it’s automatically copied.
  7. When you press Command, links become clickable.
  8. And so on…

And that’s just on the surface.

Because I wrote this for a non-developer in mind, I will omit technical details everywhere they are not required. And if you’re still not as satiated as you’d like to be, the citations at the far bottom reveal everything (For example, excellent globbing).

Wait… where were we again?

Fig 2. Terminal that comes default with most Macs

Let’s take Fig 2 as a starting point, cool? This is the default shell that comes with all new Macs today. It’s good, and powerful, and can do pretty-much everything.

Before you begin to setup, let me just warn you. It might break somewhere in the middle. I’d recommend to Google the error message first. Fixed? No? Bring your laptop over here :D

Can’t? I read every reply.

I know at times it will require infinite patience out of you, and it’s completely okay to flip the tables and walk out the door.

No, thank you.

You want to be able to reset everything to the way that it was? That’s easy. Simply open the terminal, sudo yourself in it and change shell to bash. In code:

su `id -u`
chsh -s $(which bash)

You should now have a terminal that comes default with most Macs (or Ubuntu). I haven’t used Windows since they built in shell support, so I can’t say if the process is same for it.

Finally, before I flood you up with details, let’s just get a holistic sense of what’s what, why’s why, and the flow of change. Or the change of flow.

Idk. Oddly poetic for me. Let’s dive.

What’s happenin’

So you type in “Terminal” in the Finder (Command + Space shortcut) and terminal opens up. It’s this shell that talks to the OS services via command line.

For those who haven’t heard of it, Zsh is a command line shell, similar to Bash, but with many more built-in features. Many features of Zsh are available with Bash or other shells; however, Zsh does such a great job out of the box. Zsh offers -

  • Good spelling correction Zsh does not care if you write a filename in lowercase or mixed or whatever. When you hit ‘tab’ it will first try to complete on the exact match and then use a case insensitive match.
  • Path Expansion If you type cd /v/w/h then hit tab in Zsh, it will complete it for you: cd /var/www/html (of course your path must be unique).
  • Shared command history In Bash each shell has it’s own history. Zsh shares the command history with all active shells. This means you don’t have to remember where you typed that command.
  • oh-my-zsh a community driven framework for managing zsh config. Has 200+ plugins and 140+ themes.

We’ll upgrade to a new terminal, a different shell, and a new shell framework to adorn it with. 3 things. Zsh and forget.

Tsukareteimaska?

(Translation: Let’s begin!)

Time As of now, it’ll complete in 13 minutes(starting now, until the end). Think you can set a new record? Are you clocking how long it takes you? ;) I’d be glad to know your score if you do choose to time it with your smartphone :D

Outline:

  1. Install shell application
  2. Install shell
  3. Install shell framework
  4. Install shell theme
  5. Install font
  6. Install colour scheme
  7. Match my ~/.zshrc

1. Install shell application — iTerm2

iTerm possesses a handy array of options, shortcuts, and capabilities. I would also say we do a shell integration for it (Alternatively tap menu iTerm2 > Make shell integration). This step is not necessary, so don’t worry if you can’t find a suitable Linux variant for it.

2. Install shell — zsh

Run the following command in the terminal

brew install zsh zsh-completions

After installation of zsh, set it as login shell in iTerm2. You may need to run this command:

chsh -s $(which zsh)

Logout from iTerm2 and then again launch it. Type echo $0 and you will see zsh.

3. Install shell framework — oh-my-zsh

Run the following command in the terminal

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

Oh-my-zsh has numerous plugins and themes, but probably the most useful is the git integration, which is usually enabled by default. You can find this in your ~/.zshrc file, there is a line like this: plugins=(git). If git is not in the list, then you should add it. Prezto is a great alternative and you can read more here.

3.1 Install shell theme — powerlevel9k

Run the following command in the terminal

git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k.

Install instructions complete wiki — (optional) click here.

3.2 Install font — Meslo Powerline-patched

Download Meslo LG L DZ Regular Nerd Font Complete.otf and install it. Then tap menu ITerm2 > Preferences > Profiles > Text and open Change Font and select Meslo LG L DZ Regular Nerd Font Complete font. Size: 14pt.

Repo here to choose from a variety of other nerd-fonts.

3.3 Install colour scheme — Material Design

Install instructions from the master repo (click here): Download material-design-colors.itermcolors. Then tap menu iTerm2 > Preferences > Profiles > Colors Tab. Then tap Color Presets… Then tap Import… Tap material-design-colors.itermcolors file. Select material-design-colors.itermcolors from Load Presets…

3.4 Paste ~/.zshrc file

Download my ~/.zshrc (click here for paste) and replace your ~/.zshrc file with this or copy-paste the entire text off it. This is to get custom configuration I use for powerlevel9k theme.

Congratulations! :D

(Extra) 4 Install 5 must-have plugins

Tip Please don’t forget to update your ~/.zshrc once you’re done executing a plugin command. Then to enable just open a new window, or command this- source ~/.zshrc

So for example, my ~/.zshrc has this part updated:

plugins=(
git
iterm2
macports
man
osx
python
composer
zsh-syntax-highlighting
zsh-autosuggestions
)

#1 Syntax Highlighting so you won’t have to. Command:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

#2 Autosuggestion completes your commands for you. Command:

git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

Exercises

  • Try and see what Command + K does.
  • Look up plugins like fortune, cowsay, and lolcat. You can then have random ASCII cows (not really) speak fortune (not really) every time you open up a new terminal or refresh an existing one.

Were you able to do it? If not, I can give you the code if you want me to :D

Citations

a.k.a. citation a.k.a. where I “drew inspiration” (read literally copied) from

  1. github/haccks — step-by-step tutorial (click here)
  2. github/bhilburn — Show off your config (click here)
  3. github/jondot — Awesome DevEnv (click here)
  4. github/k4m4 — Terminals are sexy (click here)
  5. github/jlevy — The art of the command line (click here)
  6. project-awesome — Awesome ZSH plugins (click here)
  7. medium/ryanwhocodes — Power up your terminal’s colour scheme and productivity level! (click here)
  8. medium/alex285 — Get Powerlevel9k the most cool linux shell over (click here)
  9. medium/caulfieldOwen — You’re missing out on a better Mac terminal experience (click here)
  10. medium/Jarvski — Customizing the OSX terminal (click here)

Project links I used

--

--

42ohaan
rabbitsync

My name is Rohan Kumar, and I Ctrl + backspace a lot when I write.