rc3.org

Strong opinions, weakly held

My zsh adventure

As I discussed a few days ago, I’m always open to a better offer when it comes to tools. Yesterday, Dan Croak write a massive post describing how to set up OS X for Ruby on Rails development. In the post he points to dot files shared on GitHub by Joe Ferris, and mentions that the shell they use is zsh (an alternative to bash that’s based on ksh).

I started wondering about the allure of zsh — I’ve used bash for a long time, and when I started using it, it was the most powerful shell around. I figured that if people were leaving bash for zsh, there must be some compelling reason, and I decided to do some research.

If you’re looking for the zsh argument, Fried CPU outlines the advantages. Item number 4 on his list, “Share history across sessions” was enough to convince me to give it a shot.

After changing my shell with chsh, it was time to start tweaking the shell configuration. I went back and looked at the .zshrc mentioned in Joe Ferris’ post and then I started looking around elsewhere for more. There are a bunch of zsh configuration files at <a href=http://dotfiles.org/.zshrc”>dotfiles.org, and from among them I found _why’s particularly useful. (He has some code that updates the title bar in your Terminal window in a useful fashion that’s a must have.)

We tell ourselves that we live in a rational, scientific society, but Unix configuration files clearly indicate that’s not the case. Various snippets are passed around like bits of ancient lore, with most people who use them having no idea why they do what they do. Count me among the ignorant and possibly superstitious. (See also: sync; sync; halt.) You can find my current zshrc here, but don’t ask me how it works, yet.

The coolest trick I’ve seen zsh pull so far involves svn add. zsh is smart enough to include only files that have not yet been added in the tab completion list when you hit tab after svn add. So if you have a directory of 10 files and only one of them is new, zsh is smart enough to choose that file when you hit tab. I love little bits of brilliance like that.

The secret is that zsh provides a highly extensible system for customizing tab completion, so there are tab completion packages for many tools that handle the special cases. (zsh’s autocompletion library for the kill command is somewhat famous.)

Playing with zsh is the best geeky distraction I’ve found in some time. I’d urge you to check it out.

5 Comments

  1. While I know that bash_completion is only a shadow of zsh, it does provide the advantage of not having to change systems.

  2. While exploring zsh (and giving some love to my other long-neglected dotfiles), I’m trying to only add things one at a time, so I can actually understand what they’re all doing. It makes it a lot more more rewarding as a learning experience. That said, we’ll see how long it takes for me to start pasting junk in wholesale.

  3. the link “dotfile.org” has a stray ” at the end.

    @Sean: what do you mean by “changing systems”?

  4. Sounds pretty cool, but I spend so little time at the command line these days that I can’t see I’d use it enough myself to switch. For good or ill, I live in Eclipse 95% of the time.

    However, the bit about not living in a rational, scientific world is very true. That’s why I always admired Perl, for admitting that the world is not a perfectly symmetrical problem that can be attacked by any Turing-complete language with exactly the same usefulness. If that were true we’d still be programming assembler.

    Perl, and from the sounds of it zsh, admit that there is complexity and unevenness in the world. Making tab-completion work exactly the same way for all commands is very consistent, but it’s not as helpful as making it work differently for different commands and avoiding doing things that you almost never mean to do. I think we’d be better off if more programmers thought about things this way rather than thinking that all problems must be solved in the most general way possible even at the expense of usability.

  5. I leookd it up and it bypasses security checks on files. Where normally you can only use completion files owned by root or your user. This allows you to use any file.I don’t think I consciously added the flag, was just part of a code snippet I found when I was first using ZSH.

Leave a Reply

Your email address will not be published.

*

© 2016 rc3.org

Theme by Anders NorenUp ↑