zsh the ultimate shell
I came upon a new shell call 'zsh'. It just rocks. It makes using command line much easier and more proficient. So what is zsh? The Z shell (zsh) is a Unix shell that can be used as an interactive login shell and as a powerful command interpreter for shell scripting. Zsh can be thought of as ...
I came upon a new shell call 'zsh'. It just rocks. It makes using command line much easier and more proficient.
So what is zsh?
The Z shell (zsh) is a Unix shell that can be used as an interactive login shell and as a powerful command interpreter for shell scripting. Zsh can be thought of as an extended Bourne shell with a large number of improvements, including some features of bash, ksh, and tcsh.
History
Paul Falstad wrote the first version of zsh in 1990 while as a student at Princeton University.The name zsh derives from the name of Yale professor Zhong Shao (then an Assistant Professor at Princeton University) — Paul Falstad regarded Shao's login-id, "zsh", as a good name for a shell.
How to install zsh?
Open a new terminal and paste the following code:
sudo apt-get update sudo apt-get install zsh sudo apt-get install git-core sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
You'll see 'Oh my zsh' if it completes successfully. Let’s make sure ZSH is installed now.
Make sure it works completely
Open terminal and paste the following code:
whereis zsh zsh: /bin/zsh /usr/bin/zsh /etc/zsh /usr/bin/X11/zsh /usr/share/zsh
If ZSH isn’t found then remove the .oh-my-zsh folder from your home folder and start over again.
If ZSH is found then the install script is failing to change the default shell. You can set ZSH as the default shell manually for the current user with this command.
sudo chsh -s $(which zsh) $(whoami)
Note: After using chsh you might have to log out and log back in again to see the changes persist.
What is it that make zsh stand out?
Features of note include:
- Programmable command-line completion that can help the user type both options and arguments for most used commands, with out-of-the-box support for several hundred commands
- Sharing of command history among all running shells
- Extended file globbing allows file specification without needing to run an external program such as find
- Improved variable/array handling
- Editing of multi-line commands in a single buffer
- Spelling correction
- Various compatibility modes, e.g. zsh can pretend to be a Bourne shell when run as /bin/sh
- Themeable prompts, including the ability to put prompt information on the right side of the screen and have it auto-hide when typing a long command
- Loadable modules, providing among other things: full TCP and Unix domain socket controls, an FTP client, and extended math functions
- Fully customizable
- The built-in where command. Works like the which command but shows all locations of the target command in the directories specified in $$ATH rather than only the one that will be used.
- Named directories. This allows the user to set up a shortcuts such as ~mydir, which then behave the way ~ and ~user do.
I will try my best to go through the above feature to demonstrate what makes zsh the ultimate shell.
1. Out-of-the-box command line completion
Suppose you want to use the command 'sudo apt-get' but you are not sure it is 'sudo apt-git' or 'sudo apt-get'. Now you type 'sudo apt' and press Tab, then you see a list of commands as below: And what is more important your cursor is still on the same point so that you can continue typing without going all over again. This is cool!
2. Sharing of command history among all running shells
This another smooth feature of szh. In standard bash shell, if you press the up arrow key, it will show only the command typed in the shell, but not the other running shell but szh is just different. The command lines are shown the same in all running shells.
3. Extended file globbing
This is one of the most important things to know and it is probably also the feature, you'd be presented with first, when reading any Z Shell globbing guide. Recursive globbing is the feature, that makes the find command superfluous in most circumstances because with this you can search the current directory including all subdirectories. To match any file that begin with 'as' within the current directory also including subdirectories, run:
ls **/as*
Here it lists all the files in current directories and subdirectories that begin with 'as'.
4. Editing of multi-line commands
Look at the following command: I can achieve this by pressing 'ESC' key and 'Enter' and every line, and what is more important and you can press arrow key up and down to go to the line you want to edit.
5. Themeable prompts
There are ton of themes which you can you to customize your shell.
In order to enable a theme, set ZSH_THEME to the name of the theme in your ~/.zshrc, before sourcing Oh My Zsh; for example: ZSH_THEME=robbyrussell If you do not want any theme enabled, just set ZSH_THEME to blank: ZSH_THEME=""
Here is my new theme:
6. Named directories
This is another fantastic feature of zsh. zsh comes with a not well-known feature called static named directories. They are declared with the hash builtin and can be refered by prepending ~ to them: Because ~folder3_path is substituted during file name expansion, it is possible to use it in any command like a regular directory, like shown above.
These are just some of the cool features of zsh, more are waiting to be explored. I hope you enjoy the reading, and what is more important is Why not start using zsh now!!!