Power up and beautify your terminal by using Zsh

 

Introduction

As a developer, working with terminal is a must. Indeed, we spend a better part of the day working on Terminal: Comparing different commits, making changes through Vim and running scripts. So why don’t we make it looks better, more comfortable and even more powerful than before? Our today blog will introduce to you Zsh- one of the most loved shell by developers.

 

An example of Zsh

An example of Zsh

Why everyone loves it ( and you should too)?

 

a) Zsh

 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. Here are some of my favorite features that Zsh offer:

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. Pretty cool right?

Path Expansion is pure win: 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 40+ plugins and lots of themes. We will talk more about it right now.

b) Oh-my-zsh

Oh My Zsh is an open source, community-driven framework for managing your Zsh configuration. We don’t think that there are any better ways to make you hooked to Oh-my-zsh than the Oh-my-zsh self introduction:

Oh My Zsh will not make you a 10x developer…but you might feel like one.

Once installed, your terminal shell will become the talk of the town or your money back! With each keystroke in your command prompt, you’ll take advantage of the hundreds of powerful plugins and beautiful themes. Strangers will come up to you in cafés and ask you, “that is amazing! are you some sort of genius?”

Sounds good to you? You  may also notice the 2 keywords in that intro: Plugins and Themes. And yes they work the same way like the plugins and themes we developing: plugins will add more functions to your shell and Themes will make it the most bad-ass terminal in your team. Oh-my-zsh is providing about more than 200 plugins and more than 140 themes from community. We are sure that you will find anything you need there.

 

 Installation

Install zsh

Open your terminal and install zsh via aptitude ( this may be your last commands you type in your old terminal 🙁 ):

Install Oh-my-zsh

You can either install Oh-my-zsh via Curl or Wget:

-via Curl

-via Wget

Make zsh your default terminal:

a) In Ubuntu:

In your terminal window, Open Edit/Profile Preferences, negative to command tab.

Check Run a custom command instead of my shell.

Custom command: zsh

Setup zsh as default shell

Setup zsh as default shell

b) In MacOs:

Go to the Users & Groups panel of the System Preferences -> Select the User -> Click the lock to make changes (bottom left corner) -> right click the current user select Advanced options… -> Select the Login Shell: /bin/zsh

 

Setup Themes and Plugins

 Setup theme

The default theme of Oh-my-zsh is “robbyrussell”, but if you want to change to another theme, you can do it by edit the file ~/.zshrc .

Open your terminal and edit that file:

This is the line define the theme: ZSH_THEME=”robbyrussell”

To use different theme, just simply change the value theme you want.

This is the list of themes: https://github.com/robbyrussell/oh-my-zsh/wiki/themes

FYI, my theme name is “aussiegeek”.

Install plugin zsh-autosuggestions

We will introduce to you our favorite Oh-my-zsh plugin: the zsh-autosuggestions. It will save you a lot of time typing by suggest command based on your history.

First you need to clone the plugin repository:

Then, enable zsh-autosuggestions  by adding it to zsh plugins list in .zshrc file:

Find the plugins section  then include our plugin in it. It would look like this:

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)

# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/

# Example format: plugins=(rails git textmate ruby lighthouse)

# Add wisely, as too many plugins slow down shell startup.

plugins=(git,zsh-autosuggestions)

The next time you open zsh, the auto suggestion will be applied. If the suggested command is the right one, just hit ‘->’ button to auto-complete it:

zsh text suggestion plugin

zsh text suggestion plugin

Now you have the auto suggestion installed. If however you don’t like the suggestion text color, you can change it in config.zsh:

Find this line and replace the default color with yours:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE=’fg=your_color_code’

To make it easier for you to choose, here is the color code table:

Color code table for zsh autosuggestion

Color code table

Take a look at other cool plugins here: https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins

For more information, check these references:

zsh-users/zsh

zsh-users/zsh-autosuggestions

That’s all for today. If you have any comment, don’t hesitate to express it here. Good luck and happy coding!

Share

Comments (2)

  1. RonaldFen
    viagrasansordonnancefr.com viagrasansordonnancefr
  2. Logan
    Good blog, i will leave the default terminal now. Cool shell incoming.

Speak Your Mind

+ 62 = 68