Keep your command line DRY
I had typed “bundle exec” thousands of times, and I was so annoyed by the repetition that I was ready to slap my grandmother. But she’s a very nice lady, and that wouldn’t have helped. Instead, I added some bash aliases. Now I can type r s
and bundler fires up my Rails development server. Everyone’s heard of bash aliases, but in my experience, few actually use them.
Here are my bundler aliases. Put them in your ~/.bash_aliases
or ~/.bashrc
file. They’ll load automatically every time you log in. (But until you log out and then back in, you’ll have to run source ~/.bash_aliases
to load them.)
My ~/.bash_aliases file
alias b='bundle'
alias be='bundle exec'
alias bi='bundle install'
# Even shorter!
alias e='bundle exec'
alias i='bundle install'
# Get rid of rails and rake too!
alias r='bundle exec rails'
alias k='bundle exec rake'
In use
# "bundle exec rails s" now looks like
be rails s
# or the slightly briefer
e rails s
# or the megre
r s
# "bundle exec rake db:migrate" now looks like
be rake db:migrate
# or the slightly briefer
e rake db:migrate
# or merely
k db:migrate
Remember, you’re a programmer, and you should never type the same thing twice. Go forth and alias!