Z shell : you’ll wonder why you never used it earlier
Recently I saw a presentation by Brendon Rapp titled “Why Z shell(zsh) is cooler than your shell” and I must say I was intrigued by zsh. I took it for a test drive and never turned back from it. zsh has been a great discovery and is my default shell now. While I’m no expert in zsh, I’d like to share what I found pretty cool about zsh.
1. Path completion
Auto-complete is one of the greatest features of zsh. Type in the following at zsh prompt …
zsh % cd /u/lo/b
… and press tab. Neat stuff right?
Type this one out …
zsh % cd /u/l/b
and press tab twice. Even cooler isn’t it?
2. cd completion
This is definitely the best thing I like about zsh. Type “cd” without quotes at prompt and press tab. Compare that with the bash’s behaviour for the same.
3. Command correction
You type one long command with all it’s arguments and then the command is wrong. Of course, you can always go back in history and correct the command but if your shell will do, why bother? Try this out.
zsh % vm one two three
4. Path replacement
Consider this scenario.
zsh % cd /usr/local/share
Oh but you wanted to go to /usr/local/bin and not /usr/local/share. Easy way to do this:
zsh % cd share bin
zsh % pwd
Neat eh? This is even cooler if you were in a path like /www/site1/media/css/main and want to change to /www/site2/media/css/main:
zsh % cd site1 site2
5. Rename multiple files based on pattern matching
Suppose you wanted to rename all .txt files to .html for some reason. In bash, you’d have to write a small script to remove the old extension and add new extension(using cut or some other means). In zsh, you’d do something like this:
zsh % ls
one.txt two.txt three.txt
zsh % zmv “(*).txt” “$1.html”
zsh % ls
one.html two.html three.html
6. Navigating history
Going back in history is really cool. I’d let you find out for yourself. Type “cd” at the prompt and press up arrow.
7. Syntax highlighting
zsh-syntax-highlighting is one cool plugin available here. After you install it, just watch as you type “netstat”.
8. zsh themes
oh-my-zsh is a collection of zsh configurations(themes, plugins, functions, helpers etc) contributed by several users that has been forked on github nearly 4000 times as of writing this post. It’s primarily for developers but there are some awesome plugins that even support searching internet from command line(nothing fancy – type in a search engine and search term, then a browser opens with the correct search URL. Neat stuff though :)!). There are some real cool stuff that you can do if you get your hands dirty with it. I wrote my own theme for zsh and customized it by combining what I liked of existent themes.
This was a short introduction to zsh and probably an incomplete one – there are probably tons of features I am unaware of but I hope this helps you get started with it.
Leave a comment if there is something really cool about zsh that you would like to share with me. Thanks!