Click to See Complete Forum and Search --> : Give the command line even more power with zsh 4


SubPar
11-13-2001, 11:44 PM
Most people out there are using bash, and I really don't know why. I've recently discovered the amazing power of zsh (http://www.zsh.org/)'s programmable completion system. All it takes to enable hundreds of pre-made completions for common commands is this in the /etc/zshenv file:

autoload -U compinit
compinit

With this enabled, pressing tab will do different things depending on what command precedes it. Here's an example:

[root@typhoon /usr/src/gnome]# ls
CVS/ gnome.txt packages/ patches/ wget.list
[root@typhoon /usr/src/gnome]# cd <TAB>
CVS/ packages/ patches/
[root@typhoon /usr/src/gnome]# cd /usr/local/tmp
[root@typhoon /usr/local/tmp]# ls
foo.rpm foo.tar.bz2 foo.tar.gz
[root@typhoon /usr/local/tmp]# rpm -i <TAB>
foo.rpm ftp:// http://
[root@typhoon /usr/local/tmp]# tar xzvf <TAB>
[root@typhoon /usr/local/tmp]# tar xzvf foo.tar.gz

Similarly, pressing tab after "tar xyvf" will autocomplete with foo.tar.bz2. There are many other examples:

- kill completes with process IDs
- killall completes with the names of running programs
- cvs completes with commands, module names and tags depending on what's already typed
- make completes with targets in the current directory's Makefile
- shell scripts (i.e. configure scripts) complete with their command line options
- links and lynx complete with html files
- man completes with man pages (and groks number options so that typing "man 5 g<TAB>" returns a list of *.5 man pages that start with the letter g)
- su completes with usernames

Really, I could go on for a loooooong time.

And zsh is very customizable. Want to cycle through completions instead of list them? You can do that. How about list on the first press and cycle through on the second press? Yup, that, too. Want an informational prompt on the right of the screen? You can do that. I put the last exit code, the current terminal and the time on the right.

Or how about recursive and intelligent wildcarding? In zsh, "ls **/*foo*" is equivalent to "find . -name "*foo*" -print", but with a lot fewer keystrokes. You can append control characters to the end to get only certain types of matches. (.) returns only regular files. (@) is for symlinks, (/) is for directories, and so on.

An application of this? Sure. Let's say you're compiling a C++ program that doesn't support objprelink but could benefit from it (many KDE apps are like this). You have to run objprelink on each object file after running make, and there's two single-command ways to do that:

find . -name "*o" -type f -exec objprelink {} \;

or

objprelink **/*o(.)

Which looks easier to you?

Anyway, if you think the command line had a ton of power before, you should try zsh (http://www.zsh.org/). Trust me, you won't go back.

manual_overide
11-14-2001, 12:28 PM
All this for only 39.95??!!

You must be crazy!!!

bdg1983
11-17-2001, 10:58 AM
My distro (Caldera) already includes zsh version 3.1.9. All that should be required is to change the default shell for the user either using a gui user admin config tool of your choice, or manually change the users default shell in /etc/passwd from /bin/bash to /bin/zsh.

ViMan
09-16-2002, 05:03 PM
I sometimes use zsh (4.04). But I have the problem that when I su from a normal user to root, it kind of messes up my terminal screen (3 lines worth of %s, {s and }s. Any suggestions on how to solve this problem? Other than that, it's a very powerful shell.