Hello.

Web developer / Occasional Writer

Zsh... oh my

When I first started using Gnu/Linux, I wondered if there is a way to improve the terminal experience. Z shell or otherwise known as Zsh was among the first things I stumbled upon.

What is Zsh?

Zsh is a shell (The language we use in a terminal), you may be familiar with bash which is the default for most linux distros including Ubuntu. Zsh is also available for Mac, and Windows(if you are up for the chalenge). A lot of Zsh’s power lies with a framework called oh-my-zsh.

Why zsh?? We already got bash…

Well there are quite a few of reason why zsh is AWSOME! But lets get started with these.

  • Convenience
  • Customization
  • Community

Convenience

What if whenever you wanted to access a directory all you had to do is write it down, Without having to press cd every time.
What if you didn’t even have to write the whole directory? What if you could just write $ Dow hit Tab , Enter
and find yourself in the Downloads directory.
What if you could write $ Do/M/Bob hit Tab and switch between the Downloads/Music/Bob Marley and Downloads/Music/Bob Dylan directories simply by using the Tab key and Enter

Well… zsh does all these and a lot more!!
Hitting Tab will auto-complete any command or path if it is the only one available, otherwise you can chose which one to use by Tab and Enter the one you want. You can use it for auto-completing paths and almost anything else.
command -- + Tab can be really convenient for seeing the options of a command.

Path replacement, lets say we have these 2 directories
/server/www/website1/current/vendor
/server/www/website2/current/vendor
and want to go from the first one to the second, all we need to do is type
$ cd website1 website2 and we will move to the second directory!
Awesome right?

Another cool thing zsh knows how to do is approximation. Lets say I’ve written
$ Downloafs/Books, Tab to the rescue!! Hit it and it will fix your path to Downloads/Books!

Customization

If you are familiar with bash you probably know about .bashrc. It is a file kept in your user directory, with all your bash customization. And custom scripts.

Like bash, zsh uses a file called .zshrc. But has an improved the alias command among other things.

With alias you can set a “sortcut” for a command. In your .zshrc you can type something like,
alias shortcut = "lengthy_command /really/long/path -option1 --option2"
then you can refer to that lengthy command simply by typing $ shortcut.

Zsh has improved alias with “extentions”. The suffix alias, and the global alias.
The suffix alias sets a command as default when referring to a file type.
The global alias sets a “shortcut” you can use anywhere in your shell.

To use the suffix alias you simply have to put alias -s [suffix]=[app] with [suffix] being a file type and [app] being the app you want to open it with.
For example if you type alias -s html=chomium zsh will open any .html file with chromium by referring to them like so $ my/project/index.html. A good way to use this is putting a terminal text editor like vim for all your text file types.

The global alias is also quite useful.You can make an alias you will be able to use anywhere in the command-line. It is used like this , alias -g PE="--port 1337 --environment test". Now you can use it in a rails server command, $ rails server PE --pid 54321.

Another thing you can customize is looks. With zsh you can change the way prompt looks. And if you installed oh-my-zsh there is a lot of custom themes available. Zsh also offers you the possibility to have something on the right side of the promt. Which can be a good way to show some info you might be interested in.

Community

There are a lot of great folks who constantly improve zsh! There are also a lot of great folks who make addons and plugins.

One of the most used is oh-my-zsh its a framework for zsh, it’s full of helpful functions, helpers, plugins, themes and more! Manny people use zsh just to use oh-my-zsh!! It has useful plugins for ruby , git and tons more!! I’d say oh-my-zsh is essential for zsh.

One plugin I found about recently and really enjoy is zsh-syntax-highlighting. It colors commands and paths with red to warn you when they are wrong. Making it a lot less painful when you are about to hit Enter with an error in the command. And green for anything valid.

Summing up

There are a lot of thing I did not cover in here. And a lot I do not know about yet.

If you work often with the terminal learning more about your shell can save you a lot of time. And let you do things you did not even realize earlier. In my opinion Zsh can be a huge improvement over bash espesially if you use oh-my-zsh.

comments powered by Disqus