Automatically setup environmental vars when `cd`ing into a specific directory

With many webapps depending on environmental vars for things like authentication and environment-specific config, it can be a pain to get those vars setup on a local dev machine. A common pattern is to provide a default when the variable is missing.

I like to avoid putting passwords in source code, so I went searching for a way to auto-setup the vars upon entering a directory in terminal. After a hint at chpwd from #zsh I landed on wayneeseguin's gist serving that very purpose. I forked it to add a tiny improvement based on another suggestion from the #zsh folks, and ended up with this simple solution in my ~/.zshrc.

Now I can toss a .set_env in any directory, add it to .gitignore and have a quick, clean way of setting up my ENV.

Fast jQuery API lookups with Alfred

Alfred is an excellent OS X utility that lets you launch apps, run quick searches, control itunes and more. I frequently look up docs on jQuery's API so rather than typing "jquery nth-child" in Google then clicking the first result, I wired up an Alfred Custom Search to pull up Google's first result when I type jq [search term].

Alfred

Search URL: http://www.google.com/search?btnI=1&q=site:http://api.jquery.com/+{query}

Now when I type jq not in Alfred, I land on http://api.jquery.com/not-selector/

tmux on zsh

I recently discovered the most excellent tmux:

tmux is a terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.

I dabbled with screen previously but abandon it because it didn't actually improve my workflow much over Terminal.app's tabs. tmux, however, supports horizontal and vertical splits! This allows me to work the same way on terminal that I do in vim.

Screen_shot_2010-11-29_at_2

I ripped some pieces from various configs around the net:

On Business

It is the customer who determines what a business is. It is the customer alone whose willingness to pay for a good or a service converts economic resources into wealth, things into goods.

Peter Drucker

Project Directory Aliasing for Quick Terminal Access

I build a lot of sites for a lot of different clients and have been perfecting my directory structure over the last few years. Because I heavily rely on Terminal to work on projects, I need very fast access requiring little thought to my project directories. At the same time I need projects organized by client so I use this rather obvious structure (these are not my actual clientsI wish!):

Keeping directory names lowercase and avoiding spaces makes for easier tab-completion on terminal.

Even so, typing cd ~/work/rivendell_bicycle_works/rivendell.com (albeit only actually typing cd ~/wo[tab]/riv[tab]/riv[tab]) is too much work when my mind is full of code and I need to get somewhere quick on a new terminal.

Enter aliasing. Aliasing allows me to open a new terminal and type cd riv[tab] and find myself in ~/work/rivendell_bicycle_works/rivendell.com. To facilitate this surprisingly useful ability, I setup an alias at the start of each new project.

When I no longer need quick access to a project, I can just delete the alias to keep my home directly clean(ish).

 

 

From TextMate to Vim

TextMate is a great all-purpose text editor, but it really isn't very good at advanced text manipulation or navigation.  Having dabbled in emacs and its far superior text navigation commands, I found myself getting increasingly frustrated with TextMate's very basic commands. Having to use arrow keys and fully move my right hand away from home row is unacceptable. 

I unsuccessfully tried to switch to emacs. I found it bloated and clunky with awkward configuration and poor defaults, and quickly switched back to TextMate. I finally decided to give vim a try, and was surprised at how decent it was despite the steep learning curve. It has an elegance that emacs seems to lack. After two days of using it on a rails project I made the decision to commit to vim and invest in learning its many motions and commands.

Here are some great resources I used to get started:
  • MacVim - the popular graphical vim for mac
  • PeepOpen - this is the main reason I chose to use MacVim over the terminal vim. If you're coming from TextMate, you'll definitely want the awesome CMD+T shortcut it provides (and if you don't know what I'm talking about, prepare to become addicted)
  • rails.vim - an essential plugin for rails developers
  • snipmate.vim - an excellent snippets plugin that will feel very familiar to TextMate users
  • Color Sampler Pack - a massive collection of excellent themes for vim
  • VI Cheat Sheet - an excellent cheat sheet designed by GoSquared for Smashing Magazine
The two main vim config files are ~/.vimrc and ~/.gvimrc. MacVim will read both, so you'll want to put generic options in .vimrc and options that only apply to a graphical vim (such as the themes linked above) in .gvimrc.

A few learning references I found especially helpful are:

Update: A few excellent vim configuration walkthroughs were posted after this. These two posts are a must for getting your .vimrc in order!