Peter's Site

  • Homepage
  • Login

Mar 20: ZSH madness

Ok, it's geek time now. If you don't know what a unix shell is, please scroll down, there are some non-geek blog posts with pictures and stuff. ;-)
After Sipprecht showed me his pimped ZSH prompt, my first thought was: "How ugly!", but a second look revealed some interesting features that prompted me to explore the Z shell a little bit further.

ZSH was introduced 1990 by Paul Falstad (OMG: what a geek, look at his geocaching.com stats!) as an enhancement of the bourne shell. It can be used interactively (i.e. you type commands) and as a scripting language. Besides being fully compatible with the bash shell, the Z shell has some original features and behaves much smarter in some situations. The most prominent changes that I encountered so far are:

The Prompt
It's possible to specify a left and a right prompt. The right prompt will disappear when typing long lines. Prompts are really a matter of taste, and these options make a customization of the prompt easier. My prompt now looks like this, with the working directory on the left and the time on the right. Note how zsh shows other user's homes with ~user instead of /path/to/the/user/dir.
Tab Completion
So that's the killer: If you deal with several files/dirs starting with the same characters and hit the Tab key, bash shows you a list of alternatives and you have to figure out by yourself the difference in the name and type an appropriate character to narrow the file list down. Very annoying. Especially when dealing with long similar file names, this behavior takes forever to find a single file. But zsh comes to the rescue: If you press Tab once, you see the list of alternatives and by hitting Tab again you can cycle through all the alternatives! With menu completion enabled, one can even navigate through the file list with the cursor keys and select the target.
Additionally zsh can expand substrings of file names. Say you have many P01XXXX.jpg files in your picture directory and want to pick P012344.jpg, then you could type 44 and press Tab and the shell will expand it to all files with 44 somewhere in their name.
Globbing a.k.a. Wildcard Expansion
Second killer: Everybody knows how to list a subset of all files in a directory by specifying a pattern, e.g. doing ls *.java to list all files ending with .java. If we wanted to list all java files, which reside in subdirectories, we need the help of find: find . -name "*.java". Not so in zsh which provides additional operators in file patterns. Here we use **/, and it will search all directories recursively: ls **/*.java.
Another huge advantage: After we type a pattern and hit Tab, if one or more files match the pattern, zsh replaces the pattern with a list of the matching filenames! Awesome. Now it's easy to see which files are affected by a pattern before executing a command, e.g. rm.

There are a lot more handy features, like auto_cd, multiple output streams, shared history and global aliases (in the above screenshot you see that I made ... to be an alias for ../..). I am still figuring out what can be done with the zsh and in the meanwhile I also learn new things about bash that I didn't knew before.

You can download my current zsh configuration and just rename the file to .zshrc and put it in your home dir.

As pointed out by some Bedenkenträger here, the main pitfall with adopting the new shell is switching back to ye olde bash, e.g. on other machines. It would probably be very annoying to hit Tab without anything happening. But these concerns should not prevent the adoption of superior technologies.
In this spirit: Happy chsh-ing.
;-)

Posted by Peter in Geek stuff Comments: (0) Trackbacks: (0)
Defined tags for this entry: linux, zsh

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

No comments


Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 

Calendar

Back February '12
Mo Tu We Th Fr Sa Su
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29        

Seiten

Frontpage
Particle Graphs
Page Graphs
Validation Graphs

Blogroll / Links

  • Mario
  • Mr. Spock
  • Roland
  • Sebastian
  • Seebi
  • Stefan
  • Sylvia
  • Uli

Categories

  • XML Copenhagen
  • XML Geek stuff
  • XML Geocaching
  • XML IMISE
  • XML L.E.
  • XML Misc
  • XML Programs
  • XML Science
  • XML Traveling


All categories

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Geocaching

Überwachung

Zensur