As a developer, working with the 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 shells by developers. Install Zsh now to boost your work efficiency!
Why everyone loves it ( and you should too)?
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.
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.
Open your terminal and install zsh via aptitude ( this may be your last commands you type in your old terminal 🙁 ):
sudo apt-get update sudo apt-get install zsh sudo apt-get install git-core
You can either install Oh-my-zsh via Curl or Wget:
sh -c "$(curl -fsSL //raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
sh -c "$(wget //raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
Make zsh your default terminal:
In your terminal window, Open Edit/Profile Preferences, negative to command tab.
Check Run a custom command instead of my shell.
Custom command: zsh
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
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: Click here.
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:
git clone git://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
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.
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:
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:
To make it easier for you to choose, here is the color code table:
Take a look at other cool plugins here.
For more information, check these references:
That’s all for today. If you have any comment, don’t hesitate to express it here. Good luck and happy coding!