Shared Zshrc File

| Comments

Over the years, I’ve had a number of requests for me to share my zshrc file with friends and coworkers. In the past, I’ve normally trimmed out the sensitive parts by hand and then e-mailed the most useful stuff. I’ve always intended to make this an easier process and I’ve finally gotten around to it.

I’ve created a new bitbucket repository to hold my shared zshrc configuration. You can get it for yourself by cloning the repository:

cd ~
hg clone

If you don’t have mercurial installed, you can just grab the compressed archive of your choice from the downloads page.

I’d suggest cloning/unzipping into your home directory, but you can put it wherever you want.

There’s an script in there that will create a new ~/.zshrc file. If you have an existing .zshrc file, just move it out of the way and run the install script (it won’t let you whack an existing file).


That created .zshrc file will load up all of my shared settings and aliases from wherever you have the shared-zshrc directory. It also will look for a host specific file where any sensitive info, or host dependent info can be added. I normally put things like my change directory and ssh aliases in here.

I probably created around half of these files myself, but I couldn’t tell you for the life of me where the majority of the other half came from. This file has accreted over the years like barnacles on a ship.

Some of these commands originally started out in either a tcsh file (or was it ksh?), I eventually moved to bash, and then a couple of years ago, a coworker showed me the wonders of zsh and I haven’t looked back.

If you’re still using bash, give zsh a try. Changing your shell is as easy as running this command:

chsh -s /bin/zsh

ZSH Specific Stuff

Most of the zsh shell configuration magic is in zshrc_compinstall. Some features include:

  • shared history across shells
  • command spelling correction
  • vastly improved tab completion of commands (including keyboard navigation of potential matches)
  • file globbing that makes finding files easy (try ls **/*.txt to recursively search for all txt files, much easier than find . -name "*.txt"
  • automatically using pushd for cd commands, use “dh” to see a history of your directories, use cd -N to go back N directories in your history (ex: cd -3)

Useful Aliases

Some of the most useful aliases in zshrc_general include:

Grep through Aliases (ag)

I often forget what some of my less often used aliases are, but I know what commands they use. I’ve set up “ag” (alias grep) to help me search through my aliases and find the right one:

% ag python
webshare='python -m SimpleHTTPServer'

Grepping History (gh)

Great for finding commands in your history that you can only remember part of.

  gh grails
  582  grails create-app testDates
  584  grails create-domain-class Foo
  585  grails generate-all Foo
  587  cd grails-app
  591  grails generate-views Foo
  592  grails run-app

Global Alias - GV - to “grep -v”

Grep is great for finding things, but often you find too much and need to slice stuff out. If you use “grep -v” that finds all lines that don’t match a pattern. The global alias “GV” that makes this even easier.

   grep -ri foo

If that finds too much stuff (say catalina log files and svn files that you don’t care about), just slice them out with GV:

   grep -ri foo GV svn GV catalina

That will remove any lines that have “svn” or “catalina” anywhere in them (including the file name).

I think that rc files tend to be very personal things, what works for me likely won’t work for you exactly as it is. But I also love to look at other people’s rc files to grab the things that look interesting. Feel free to poke through mine and grab whatever strikes your fancy.

There’s a ton of other stuff in there that I use every day, including sections specific to version control (svn and hg) as well as groovy/grails shortcuts. Feel free to poke around and ask me any questions about what something does.