giant robots smashing into other giant robots

We are thoughtbot. We make web & mobile apps.

Tagged:

Comments (View)

How To Use Arguments In a Rake Task

I came across this today. You can write Rake tasks that accept arguments, called like this:

rake tweets:send[cpytel]

You define the rask task like this:

namespace :tweets do
  desc 'Send some tweets to a user'
  task :send, [:username] => [:environment] do |t, args|
    Tweet.send(args[:username])
  end
end

Unfortunately, zsh can’t parse the call to the rake task correctly, so you’ll see the error:

zsh: no matches found: tweets:send[cpytel]

So you’ll need to run it like this:

rake tweets:send\[cpytel\]

Or this:

rake 'tweets:send[cpytel]'

Tagged:

Comments (View)

Bracket Expansion

Let’s say you want to update capybara and capybara-webkit. You’d normally type this:

gem update capybara capybara-webkit

But you’re busy, you don’t have time to type “capybara” twice. Let’s see what tab completion has for us:

gem update capybara{,-webkit}

The bracket expression expands to the same thing as above because the brackets expand to "capybara" + "" and "capybara" + "-webkit". If you’re in ZSH, you can press the TAB key (gem update capybara{,-webkit}<TAB>) and it will expand the expression for you inline. Bash users, this will still work for you, even without the neat TAB trick.

Tagged:

Comments (View)

I learned to alias shell commands with Hooked on Phonics

Do your co-workers snicker at your sentence-length shell aliases? I’m here to tell you it’s okay because my aliases border on the Dostoyevskian, too.

Some commands you do a thousand times a day. They deserve super-short aliases:

alias be="bundle exec"
alias s="bundle exec rspec"
alias cuc="bundle exec cucumber"

Like h() or t() in Rails, the more often you invoke a command, the more acceptable it becomes to have a short, cryptic alias.

However, there’s a class of commands I find myself running about 1-20 times a day: interacting with our staging and production environments on Heroku:

# Heroku staging
alias staging='heroku run console --remote staging'
alias staging-process='watch heroku ps --remote staging'
alias staging-releases='heroku releases --remote staging'
alias staging-tail='heroku logs --tail --remote staging'

# Heroku production
alias production='heroku run console --remote production'
alias production-process='watch bundle exec heroku ps --remote production'
alias production-releases='heroku releases --remote production'
alias production-tail='heroku logs --tail --remote production'

# Heroku databases
alias db-pull-staging='heroku db:pull --remote staging --confirm `basename $PWD`-staging'
alias db-pull-production='heroku db:pull --remote production --confirm `basename $PWD`-production'
alias db-copy-production-to-staging='heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote production` --remote staging  --confirm `basename $PWD`-staging'
alias db-backup-production='heroku pgbackups:capture --remote production'
alias db-backups='heroku pgbackups --remote production'

Here’s where Neckbeard next to you silently pities your Fisher-Price programming style. What self-respecting programmer would type all that?!

Well, through the magic of autocompletion, you never type more than a few characters for each command. They might look goofy, but they’re memorable.

If you’d like these aliases and other goodies, they’re packaged up in our dotfiles.

Then, the next time you feel your pair programming partner smirking over your shoulder, just tell ‘em: “I learned to alias shell commands with Hooked on Phonics!”

Tagged:

Comments (View)

cd’ing to frequently-used directories in ZSH

Josh just dropped some sweet, sweet ZSH knowledge. I spend a lot of time in the directories under $HOME/thoughtbot/ and $HOME/src, and to get there I type (for example) cd ~/thoughtbot/hoptoad. There is a better way!

First, add this to your ~/.zshrc and source it:

setopt auto_cd
cdpath=($HOME/thoughtbot $HOME/src)

Obviously, use different paths in cdpath depending on which directories you cd into a lot.

Now let’s try it out:


$ cd rspec-core # Autocompleted from rspe<TAB>
$ pwd
/Users/gabe/src/rspec-core
$ cd hoptoad
$ pwd
/Users/gabe/thoughtbot/hoptoad

Seriously, check out your coworkers’ dotfiles. It can improve your workflow efficiency by an order of magnitude. Like most of the Thoughtbot crew, Josh keeps his dotfiles on Github.

Tagged:

Comments (View)

Font Battle 2011

A recent straw poll of text editor fonts at thoughtbot found these results. Not all thoughtbot precincts have reported in. Perhaps you’d like to explore some new font options for those walls of text you stare at for 8+ hours daily.

Some links to these fonts: