DEV Community

Stephen Chiang
Stephen Chiang

Posted on • Originally published at chiangs.ninja on

How I bling-ified my terminal

Do not be afraid of the terminal, it’s amazing!

– said no beginner ever.

First and foremost, this isn’t going to make you a better developer, but it’s an awesome quick and easy facelift you can do to instantly make your time in the console time pleasing to the eye and a and make you feel like as if you are developer level 2000. At the very least, you’ll get some more utility and conveniences out of this (for those of you, like me, who have a bad habit of forgetting to check what branch you are on before working).

Before
After

As I spend more time developing, I find myself staring into my console more and more. I would like to say that I’m pretty comfortable with it now and really enjoy moving files and directories and quickly making new directory and file structures compared to the repeated right click >> new blah-blah.

A lot of you veterans have already heard of different shells, so this is for the beginners out there.

What is a shell and what does it do?

For Mac and Linux distrubutions, the most common default shell provided is Bash. For those of you with Windows, it’s likely you are using PowerShell. Bash is a great shell that offers things like command and file name completion, advanced scripting features, a command history, configurable colors, command aliases, etc.

Another newer, yet very similar shell, Z shell or Zsh is what we’re going to talk about today. To read in detail about the difference between bash and zsh: Zsh vs Bash. Because I don’t really plan on writing scripts for other developers to use just yet, it’s safe me to switch of to zsh, however, it’s quite easy to switch between the two in the active terminal with:

\> exec bash or $ exec zsh
Enter fullscreen mode Exit fullscreen mode

In all honestly, I just wanted zsh for some of the convenience items like more relevant autocompletion, (try typing git <tab> with zsh) themes, plugins, and syntax-highlighting aka colorization because, like all design-minded developers out there, stuff has to look pretty and work well if I’m using it daily. I am sure the real power of zsh will become even more clearer to me as I advance.

For more details, there’s a great article here: What’s the Difference Between Bash, Zsh, and Other Linux Shells?

Customizing

The basic terminal is pretty bland, but when you replace the default Terminal app with something like iTerm2, you already off to a great start in manipulating the shell environment such as how many lines to keep in memory, or colorization of the text.

But with zsh, you can get so much more fun stuff, and it’s really easy to manage. Here’s how I did it:

TL;DR Z shell installation and customization

These steps are on Mac; just refer to the main zsh repo for instructions on other platforms like Linux and Windows. Normally zsh is included on Mac distributions, you just have to check the version. The links to the repos are at the end of this article.

Install zsh

Check if zsh is already pre-installed on your machine

You’ll want v5.1.1 or more recent

In your terminal:

zsh --version
Enter fullscreen mode Exit fullscreen mode

You should set zsh as your default shell.

Run echo $SHELL from a new terminal to confirm.

Expected result: usr/bin/zsh or similar

If not, here are the directions to install zsh: Installing ZSH

On Mac OSX, you can open the User and Groups panel and go to the advanced options for your user and set the login shell to something like usr/bin/zsh.

Insall oh-my-zsh

oh-my-zsh is just a framework for managing your zsh configuration, but it’s a really awesome framework that makes managing it really easy, it’s worth it. Get it.

The repo provides 2 ways to get it using curl and wget, check with the repo for the latest:Oh-my-zsh. There’s really great documentation on how it all works and where everything goes.

  • via curl or wget
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
Enter fullscreen mode Exit fullscreen mode

the .zshrc

This is the equivalent to the .bash_profile for bash shell, only a lot more helpful and comes with instructions on how to override the default settings. I just copied over my aliases from my .bash_profile, but you could essentially export it through the .zshrc or some like to just create a .profile that both bash and zsh can reference. Your call. But this file is awesome for aliases, which allows you to type shortcuts to frequently used directories or even remote repos, etc.

You can open this file with vim, vs code, atom, or just the plan text note pad.

∆ code ~/.zshrc

That’s it you are done, just find a theme you like, if it’s a pre-packaged one, you just change the name in the ZSH_THEME="nameOfTheme".

If you want to download a custom one or one that’s not pre-loaded, you just have to download it and place it in the custom/themes directory and then change the name and oh-my-zsh will find it for you.

Same with plugins, it comes with everything, you just have to activate it by adding their name to the plugins=() line. At the very lease you’ll want the git one.

Another favorite non-.zshrc prepackaged plugin is syntax-highlighter which tells you whether the command you are entering is correct. GitHub – zsh-users/zsh-syntax-highlighting: Fish shell like syntax highlighting for Zsh.

Just follow the directions on downloading and install and don’t forget to add it to the .zshrc file like this: source $ZSH/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

Don’t forget to ∆ source ~/.zshrc every time you make a change to this file.

Text editor integration

Of course, I also want to add it to my favorite text editor, VS Code!

In the settings file, type in shell and scroll to the bottom where you’ll see the paths set for the shell to be used by the integrated terminal: "terminal.integrated.shell.osx": "/usr/local/bin/zsh"

If it still says bash, then change it to zsh. Restart your VS Code and open the integrated terminal and it should say .zsh in the upper right of the terminal window.

At this point I observed an odd behavior where bash and zsh were visibly flipping back and forth several time, if the terminal is starting up slow for, double check your .zshrc profile and your $PATH. I had several duplicate path shims, so I had to just clear those out and now the terminal starts up instantly.

There are some really cool themes out there like any of the powerline versions, but I prefer to keep it simple. Throw up your terminal in the comments below and tell us what you are using!

links to repos and install instructions

Zsh

Oh My Zsh

Top comments (4)

Collapse
 
lifesizehuman profile image
Slater Combes

Ever since I was introduced to zsh and subsequently oh my zsh I've been obsessed with the customization of my terminal. Currently using bullet-train theme for zsh and working on building my own theme

Collapse
 
briancrink profile image
Brian Crink

I'm currently looking into the configs of the well-known Mathias’s dotfiles, zsh will be next on my list in the realm of shell customization. Thanks for the article!

Collapse
 
attkinsonjakob profile image
Jakob Attkinson

What are these dotfiles?

I wish people would write a short intro on GH xD

Collapse
 
moopet profile image
Ben Sinclair

There's very little I've found to recommend zsh over bash. There are bash completion scripts for pretty much everything, and the only real differences are in things like autocompletion of paths, which I find clunkier than just hitting tab, and conditionals when writing scripts which aren't going to be portable to most systems without forcing them to use zsh too.