Shell Fun - The switch to ZSH

So I recently switched to zsh after encouragement from a friend and wanted to share some of the possible benefits. With some help I was able to bring over some history improvements I had in bash to zsh too.

I was pointed to this blog entry that pretty much sums up some of the pros of using zsh over bash. I'm a big fan of the tab completion options available along with the auto-correction. I can do "cd public" in my home folder and it'll fix it to "cd Public".

Tab completion

The tab-completion is able to do a fancy menu selection too which I kind of like: terminal-zsh-tab1.png

You can move the selection around the arrows or control-C to cancel out. In this case I didn't type any characters yet, "GarageBand/" is the possible selection. Hitting enter will confirm. It behaves a bit different but I'm liking it.

History

One thing I did like which I didn't have setup at first was the prefix history search. The idea is you type in something like "ssh" and then can cycle through your history for anything starting with that. This makes it easy to find a previous ssh connection in this example. You can bind this behavior to a key, which I would bind to the typical history cycling of up & down. The bash history blog I linked to above mentioned this in the comments and required putting it in .inputrc. With zshrc it turns out I just needed to use it's format within zshrc itself:

bindkey "\e[B" history-beginning-search-forward
bindkey "\e[A" history-beginning-search-backward

This differed from bash's commands by the -beginning- piece being added here, otherwise it uses the previous word you typed only I believe.

My zshrc

There's a ton of stuff to learn about zsh of course, and I don't understand half of what's in my zshrc either. But I like the benefits and hopefully will slowly learn more. What I did to start is just tweak an existing one so I'll provide mine here:

My zshrc

Things it has: * A list of your servers * shortcuts to push it to the listed servers * some shortcuts to setup git for a project, including the remote copy * shortcut for cloning from my GITSERVER * tons of other useful shell functions * Sets up ls to colorize listings on linux & OS X

The zshrc is based on what Nicholas Penree gave me and thanks to him for helping improve my terminal using experience! Be sure to check the top of the file for the areas to customize.

Todo

There's some things I have yet to figure out too. Some things I'd like to figure out:

  • Detect OS X GUI access to set $EDITOR properly (mate -w only if we can open a GUI app)
  • Track changes to zshrc through git instead of just get/pushing it randomly
  • On my MBP control-A and E don't do beginning/end line like they normally do, weird!
  • Actually organize things a lot better, bindkeys are everywhere, so are various functions
07:33 PM | Tags: ,