zsh: a REALLY nice alternative for bash
June 18th, 2008 edited by TinchoArticle submitted by Danilo Martins. Guess what? We still need you to submit good articles about software you like!
After years using ZSH instead of BASH, I still don’t understand why isn’t everybody using it. ZSH is a complete shell that will certainly make your life easier. Give it a try.
First of all, you need it installed (duh). APT and its super cow powers will do this for you. You can simply use:
$ sudo apt-get install zsh
and you should be all set. Alternatively, you can install the package “zsh-beta”, but it tends to crash once in a while… ZSH is available on any repository of Debian and Ubuntu.
To try it out, you can simply type zsh, but you wouldn’t be very happy with the result. Let’s personalize it first. First of all, create a file named .zshrc
on your home directory. Inside, you should put the text listed here (note: see the commented lines —be sure to try each of them out sometime)
Editor’s note: I’ve moved the sample script to a separate link, to ease cut&paste. Also, note that if you run zsh from Debian testing/unstable for the first time without a .zshrc
file, it will greet you with an initial configuration dialog.
Now do run zsh. If you see a different prompt (specially if you did not comment the prompt lines on the .zshrc
example above), it’s working. Now, it’s time you see what you can do with this.
First example. Lets suppose you’re doing a long command (cat /etc/mailcap | grep "^audio" | sed s/mplayer/gmplayer) and forget the command syntax for the sed
program. You simply move your cursor to the command “sed” and press ALT-H. This should open the man page for sed
. After you close the man page, you will automatically be returned with the command you were typing.
Second example. You’re connecting to a remote host using SSH. You remember that you want to use the X11 forwarding, but you don’t remember how to do this. Then, you type “ssh -” and press TAB. Yes, ZSH auto-completes not only files, but also command parameters. Be sure to try it out with whatever command you want to use.
Third example. You have a SSH key to a remote host, and you wish to copy a file from there using SCP. But you do not remember exactly where the file is. You simply type “scp user@remotehost:/home/myuser/myf”, press TAB and watch ZSH doing its amazing trick. Not only ZSH auto-completes files and parameters, but also remote files (remember that for this to work you need to have the RSA/DSA key on the remote host).
Fourth example. You want to install a Debian package (I love this one), but you don’t remember (or are too lazy to) type the whole name of the package. Instead, you simply type “apt-get install mysql-client” and press TAB, and watch ZSH magically auto-completing the package name. If you have more than one, it will list all available below, and if you keep pressing TAB it will complete through each one of them, one at a time. And yes, not only ZSH auto-completes files, parameters and remote files, but it also auto-completes package names. Well, I think we had enough of the “auto-complete” examples, didn’t we?
Fifth example. Yesterday you used a loooooong command and you are too lazy to type it all again. You also do not want to press UP until it appears. Instead of it, you simply type the beginning of the command and try the ALT-P combination. ZSH will auto-complete your command from the history. You can keep using ALT-P and swapping to the previous entries. If you missed it, ALT-N gets you to the next.
Last example. You typed apt-gey install foo bar foo2 bar2 foo3 bar3 foo4 bar4 ... foo239 bar239 and pressed ENTER. Oh, shit, apt-gey does not exist. Instead of pressing UP, HOME, going to “gey” and changing it to “get”, you can simply use ^gey^get. This is a shortcut to “repeat the last command, but all occurrences of “gey” are now “get”.
If you liked the way ZSH works and want to use it as your default shell, you can always use the chsh
command, and put /usr/bin/zsh
there. It’s now your default shell.
Enjoy!
Posted in Debian, Ubuntu | 34 Comments »