I Beautified My Terminal with Zsh and Oh my Zsh!

banner

Source: unsplash.com (@6heinz3r)

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.

What is zsh? and 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, and 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.

1sudo apt -y install zsh

Check if it's successfully installed or not.

1zsh --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.

1chsh -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.

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

or,

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

After you've successfully done that, woohoo! Our terminal prompt changes. It gives auto-completion ability and switches through commands, folders, and files by pressing tab.

folder auto suggestions

Highlight prompt green when the previous command executes successfully and red when giving errors. prompt highlight based on commands

How do you feel? Is it cool?

Tweak .zshrc

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

1vim ~/.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 setting ENABLE_CORRECTION="true"
  • Auto-update time by setting UPDATE_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. auto correction

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, to find your favorite one. If you find one, that attracted to you. To add this ZSH_THEME="theme name" inside .zshrc file and save. Then run

1source ~/.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 this plugins=(git colored-man-pages) inside .zshrc file and save. Then run

1source ~/.zshrc

Now man page will look like this. highlighted manual page

  • zsh-autosuggestions

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

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

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

1source ~/.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. auto-suggestion-1

Accept by pressing the right arrow key. auto-suggestion-2

  • zsh-syntax-highlighting

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

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

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

1source ~/.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

correct command hightlighted

If it did not find the command

wrong command hightlighted

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!

Resources