9 reasons to use Zsh

  sonic0002        2012-09-28 12:46:39       10,328        0    

Like majority *nix users, I have been using bash for many years. Sometimes I feel uncomfortable with bash. I tried use some other shells as well such as ksh, tcsh and zsh which I am going to talk about. A few days ago, I found an open source project ranking in the 6th named oh-my-zsh on Github, I downloaded it and had a try with it. It's amazing. We should use zsh to replace bash now.

Why do we need to use zsh?

Here is a 4 minutes YouTube video which shows many reasons why we should switch from bash to zsh.

Reason 0 : zsh is compatible with bash

Compatible with bash means that we don't need to spend too much time learning zsh. it also means what we know about shell will not be wasted. In my mind I still think bash is the most common and standardable shell environment. So I don;t need to worry too much about switching from bash to zsh since its compatible with bash.

Reason 1 : zsh's auto complete mode is very convenient

Pressing two tab key will trigger zsh auto completion,

Reason 2 : zsh supports commonad line option auto completion

Besides directory auto completion, zsh also supports command line option auto completion, for example ls - will list all options of ls, you will never need to open a new terminal to check the manual of ls when you type the ls command but forget its options.

Reason 3 : zsh supports command parameter auto completion

Previously if I want to kill a process, what I did was first typing ps aux | grep "process name", then remembered the process id of the process, and finally kill . But with zsh, I only need to type kill , then zsh will auto display all the processes and their pids, you can select one to kill.

Other auto completion commnads are:

  • ssh , zsh will list the hostname and username you accessed before to auto complete the ssh command.
  • brew install to auto complete software package name, in addition to homebrew, it also supports port/apt-get and other package managers.

Reason 4 : zsh supports smarter directory auto completion

Previously if we want to go into a deep directory, we may need to spend some while on typing the  cd command, for example /users/pw/workspace/project/src/main/webapps/static/js. In zsh, we only need to type the first letter of each directory and subdirectory then type , for example cd /u/p/w/p/s/m/w/s/j.

Reason 5 : zsh's powerful directory switch

In the past, if we want to switch between two working directories, we need to type many cd commands, we can also try to use popd and pushd to solve this problem, but the problem is sometimes we forget to use pushd after we change the directory. zsh will remember every path you access then you can use 1 to change to the previous accessed path, 2 goes to the previous previous path...until 9, you can also type d to view the directory access history.

zsh can also be used together with autojump, autojump will record every directory you accessed and later you can use j to jump to different dirctories quickly.

Reason 6 : zsh supports global alias and suffix alias

bash's alias can only be used for command, while zsh's alias is more powerful, it can beused for part of a command.

1
2
3
4
$ alias -s log=less
$ ~/package/tomcat/log/catalina.log # Same as less ~/package/tomcat/log/catalina.log
$ alias -g PR=http_proxy=127.0.0.1:8087
$ PR curl https://twitter.com # Same as http_proxy=127.0.0.1:8087 curl https://twitter.com


Reason 7 : zsh has abundant command line prompts

In bash, we can configure $PS1 to realize many command prompts. With zsh, we can achieve multi-line prompt, right-align prompt. Also in oh-my-zsh's configuration file, there are many prompt themes to choose.

Reason 8 : zsh has more graceful syntax

If we want to configure PATH, in bash, we need to have all paths in the same line, if there are many paths, it looks messy. zsh supports more human readable configuration.

1
2
3
4
5
path=(
    ~/bin
    $path
    ~/package/smartsprites/bin
)

Install zsh

Linux users can use respective Linux version's package manager to install it.

Mac has a built-in zsh version 4.x.x, you can directly use it, you can also use homebrew to install the latest version 5.0.0. We recommend to use the latest version 5.0, it has complete support for multi bytes, this is very convenient for users out of US.

Set zsh as default shell

We can change the default shell using chsh. One thing to be noted is if you use homebrew to install the latest zsh, you need sudo to edit /etc/shells, add one line /usr/local/bin/zsh. Then use chsh to change the default shell, otherwise it will prompt /usr/local/bin/zsh is an illegal shell.

Install oh-my-zsh configuration

For an entry level zsh user, oh-my-zsh will bring big help, we highly recommend entry level users to use this configuration.

Here is an auto install command

curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh

You can also install it manually. Details can be checked here.

Some necessary plugins

autojump

A small widget for directory switching, first install autojump, then launch autojump plugin in .zshrc. It will record each directory you accessed, you can use j command to jump to one directory.

git

Git command auto completion,

osx

Provide some commands to interact with Mac OSX system. For example:

  • man-preview to check a command's manual through preview program, such as man-preview git.
  • quick-look to quickly preview a file

Source : http://lostjs.com/2012/09/27/zsh/

ZSH  ADVANTAGE  COMMAND 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

Pair programming