2012-02-23

Stop Bashing on Linux Terminal and Start Using Zsh


Zsh? Bash? Dude... WTF?
If you are new to the Linux world or haven't really been into it you might have seen or heard of such scary program - Terminal. It's basically a window to the past when everything was not ran true nice graphical user interface (GUI), but rather true text inputs or ASCII looking ugly programs. Remember Windows XP or older Windows installations? That's what we call ncurses looks. Sure I must say/write that most of the programs that use ncurses looks a lot better so sorry if I made someone angry by this comparison...

Anyway back to the point... So people uses this window to the past to use some sort of command line tools or  programs and the tool that understands those calls and runs proper programs inside that window is ussually bash... Or as I now will propose - Zsh. Why this matters? Terminal can do stuff a lot faster since typing is faster than point and click also it's distraction free and easy on your resources. Really! Therefore most of Linux wolfs heavily uses terminal.

Perfection lies in simplicity
If so - Zsh if far from perfect. Yet small and simple parts of it brings it so much closer. If you tried Zsh before, you probably haven't noticed a huge difference to the bash, also you might think that bash has better integration to current Linux distributions (better looking prompts), but under certain point of customization it becomes insignificant what integration is done for the distribution you are using and if you like personalizing stuff as much as possible, you will like Zsh.

So just change bash to Zsh?
No. Zsh alone is pretty boring (just as bash is), unless you at the end of the line of geekyness and you don't like what others has to offer, or you just don't care about using terminal.
So the magical pack is called "Oh My Zsh!", it just trows a pile of configs on top of Zsh, and allows you to change anything you like.
It adds multiple aliases (for e.a. sudo==_) and allows to use themes. Sure it also brings full configuration for Zsh after which you are able to navigate in terminal easier.

Give me samples!
O.K. For example if you previously executed 'vi foo' and then 'ls ~', after pressing up arrow you will be given command 'ls ~' just like in bash, but if you would start typing 'vi' and press up, it would give only those history results that starts with 'vi'. Cool eh?

Some more. If in your $HOME directory you have a file 'Documents', and you would start typing 'doc', press <TAB> - it would autocomplete to 'Document' fixing the first letter, sure having in mind if there would not be any documents/files starting with 'doc'. Remember in Linux capital and non-capital letters are different.

All of this was just Zsh, but combining yih "Oh My Zsh" you get good looking and smooth terminal experience. Why I say so? Because that magic pack also adds some aliases that fixes your common mistakes. For e.a. if you miss 'cd' at the beginning of command and you would just type folder name it would automatically go to that directory.

Or for example have you ever typed 'sl' instead of 'ls'? It also fixes that (sorry steam locomotive fans).

For more complicated mistypes ('emaxs' instead of 'emacs') in case when Zsh would not find 'emaxs' executable it would ask if you mistyped 'emaxs' and would like to fix it to 'emacs' [Y/N]? Now thats really neat.

Thats it? Bash have awesome configs too!
At first those things looks small, but latter on they become so important that you will stick Zsh in every single of your machines, believe me...

Also one of now my favorite Zsh features is globbing.

Usually if you use wildcard '*' in a command you probably referring to every single file in (lets say) current directory, Zsh allows to use '**/*' that means not only every file in current directory but also all the files within folders that are in current directory. And to objection to your -R comment, just have in mind that not all tools (especially small ones) have support for recursion.

As with wildcard (*) you can use full patters with this. '**/*.py' will find all .py files.

Zsh has really good regular expression engine build in so finding files for commands is really easy.

It can also give you files modified within past 24 hours or with certain permissions just out of a simple shell, completely replacing 'find' and pipes (|).

All of it is nicely covered here by Stanford university: http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=zsh-globbing&speed=100

So How to Install This?
Simple, just install Zsh (It should be available on most of major/alive distribution within standard packages). Then install git if you don't have it.

Finally follow instructions on https://github.com/robbyrussell/oh-my-zsh.

P.S. I do trust automated installer option - it works.

Anything else?
Just look at the Oh my zsh wiki (first link above). Also you might look up Zsh reddit community at http://reddit.com/r/zsh besides that - just give it a week or so, you'll like it.

Also as suggested by Alexander these links are also worth checking out if you're interested in scripting:
http://www.linux-mag.com/id/1079/
http://grml.org/zsh/zsh-lovers.html

Happy usage, Over and Out.
JackLeo