I Beautified My Ubuntu Terminal with Zsh and Oh my Zsh!

Akibur Rahman (Akib)
JavaScript in Plain English
5 min readMay 9, 2020

--

Photo by Gabriel Heinzer on Unsplash

Read more articles on my Personal Blog.

If you spend lots of time on your terminal like me, it’s time to consider making your terminal look better. This can help you to feel more focused and thus improve your productivity, as well as save your time and energy.

If you spend lots of time on the terminal, why does it look so dull? Let's make it pretty.

Why zsh?

Okay. Great question. I appreciate it.

zsh has a powerful default auto-completion feature, as well as more configuration options. The zsh configuration has an open-source, community-driven framework oh my zshand it has thousands of helpful functions, helpers, plugins, themes.zsh is also compatible with bash syntax.

Install Zsh

In our system default shell is bash. To use zsh, we have to change our default shell bash to zsh. To do that, we have to install zsh on our system. Open your terminal and execute this command.

sudo apt -y install zsh

Check if it’s successfully installed or not.

zsh --version

If you get any errors, try to Google and resolve them.

Change shell

Our system’s default shell is bash. We have to change it to zsh.

chsh -s $(which zsh)

chsh stands change shell. After changing the shell, we have logged out from our terminal or restarted the PC. Then, when you open the terminal again, zsh will prompt the zsh configuration function. We can follow the instruction to configure the shell. But we want to quit and do nothing by pressing 0.

Install Oh My Zsh!

We can install it using two ways — curl and wget. You can choose whichever you prefer.

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

or,

sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

After you’ve successfully done that, woohoo! Our terminal prompt changes. Now play around.

It gives auto-completion ability and switches through commands, folders, and files by pressing tab.

Highlight prompt green when the previous command executes successfully and red when giving errors.

How do you feel? Is it cool?

Tweak .zshrc

To do that, we will tweak our .zshrc file.

vim ~/.zshrc

You see, there are many configurations that are commented out. We need to change some of them.

  • Comment out $PATH
  • Enable auto-correction by settingENABLE_CORRECTION=”true”
  • Auto-update time by settingUPDATE_ZSH_DAYS="how many days you prefer"
  • Other bash configurations like nvm, add them to the end of the file (if you have).

Auto-correction will suggest a command correction if it detects a mistyped command.

The 4 options are:

  • n (no): run the mistyped command
  • y (yes): run the suggested command
  • a (abort): stop and do nothing
  • e (edit): edit your command before re-running it

Change Theme

If you want to change the theme, you can explore here your favorite one. If you find one. To add this ZSH_THEME=”theme name” inside .zshrc file and save. Then run

source ~/.zshrc

The default one is my favorite. You can find your favorite themes from here.

Add Plugins

Now we want to make it more cool using oh my zsh plugins. We have already git plugin added by our default theme.

  • colored-man-pages

We need to read details about commands often, to do that we use man command. That is hard to read. colored-man-pages help us read easily. This plugin highlight text.

To add thisplugins=(git colored-man-pages) inside .zshrc file and save. Then run

source ~/.zshrc

Now man page will look like this.

  • zsh-autosuggestions

colored-man-pages was a default install. But we have to add it. To do clone the plugin inside that.

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Then add thisplugins=(git colored-man-pages zsh-autosuggestions) inside .zshrc file and save. Then run

source ~/.zshrc

This plugin is very handy when you want to run the previous command again. It will show matching command from our commands history. We can switch commands using the arrow keys.

When I type cd I will get immediate suggestions.

Accept by pressing the right arrow key.

  • zsh-syntax-highlighting

we have to add it. To do clone the plugin inside that.

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Then add thisplugins=(git colored-man-pages zsh-autosuggestions zsh-syntax-highlighting) inside .zshrc file and save. Then run

source ~/.zshrc

It highlights command within the command line. It also colorizes the name of the command you type in green if it is found, and in red if not.

If it found the command

If it did not find the command

Last word

Here are my favorite plugins and themes. You can find your favorite themes from here and plugins from here. And let me know what is your favorite theme and plugin.

Welcome to the beautiful terminal. Enjoy it!

If you are interested, read more articles on my Personal Blog.

More content at plainenglish.io

--

--