Wednesday, March 7, 2012

Moving from Bash to ZSH




I have Stopped using Bash and am now using ZSH as my new shell of Choice.
ZSH has many awesome features that make it a No brainer (for me anyway) to make the switch

Here's what I love about ZSH

1:) Your History is shared across sessions. Multiple simultaneously running zsh sessions can share history with each other. how many times have you looked into your bash history to find a recent command that you used, only to find that that command was run on a different terminal session and is no longer available to you.

2:) Tab Auto completion works between remote machines over SSH.

rsync -avr remotemachine:/home/cgerada/Documents/very/long/directory/na (at this point you can hit tab and provided that you connect to your remote host using ssh Key authentication instead of password authentication  zsh will autocomplete for you.

3:)No need to type cd to change into a Directory.
/home/cgerada/directory   enter

will change to /home/cgerada/directory  for you.
Considering how often you use the cd command, this is a real time saver.

4:) Tab auto completion works for command options
     rsync -av (hit tab here) will show you all possible options for the rsync command

5:) Built in Spell check
     How many times have you typed something like aptg-et or other mangled commands? Well,
     if you do that in zsh,You  get a message asking: “zsh: correct 'aptg-et' to 'apt-get' [nyae]?

6:) Built in pager.
     If your Lazy like me. And I think you are.  zsh comes with a pager directly in the shell. This means you
     can type things like " > README  and it is equivalent to less README or cat README | less"


7:)Right hand prompt
    Zsh supports a second (right hand prompt) great for adding the date and time (see screen shot above)
    or if you own a laptop you can also display your Battery capacity.  The right hand prompt will not get in
    your way as it disappears when your typing reaches it. or you can just not enable it if you don't want it.

8:) Known hosts auto completion. ZSH can even tab autocomplete hostname entries of remote machines that  
     you connect to from your .ssh/knownhosts file.

     in fact auto completion in all areas is far more superior in ZSH.

9:) Extension aliases

alias -s doc=libreoffice





putting the above in your .zshrc file allows you to open up a .doc file simply by typing its filename. eg

officedoc.doc  [enter]

will open up officedoc.doc using libre office (in Bash you would have had to type

libreoffice officedoc.doc
you can do the same for all extensions eg
alias -s pdf=evince
                      
ZSH has loads more awesome features, and is highly customizable .  it behaves extremly similar to bash, in fact you can use it exactly the way you use bash and not learn or change a single thing and you won't be missing anything.

Right, so if you are convinced to make the change and jump right in.

install zsh by typing  yum install zsh or apt-get install zsh.

once installed simply type
chsh to change your shell  .
you will be asked for your user password
once typed in correctly you will be asked
New shell [/bin/bash]
type /bin/zsh   enter

and the next time you log into your shell with your username you will be in the ZSH shell.

If for what ever reason, you do not like zsh and want to revert back to bash
simply type
chsh
enter your password once again
and then type
/bin/bash

will change your shell back to Bash.











No comments: