Last Updated: January 06, 2019
·
7.244K
· rafbm

Shell alias to stop writing `bundle exec`

Bundler is awesome. It’s the one true way to ensure proper dependency management for Ruby projects. Yet, it can be painful to type bundle exec before shell commands.

Sure, binstubs exist, but I don’t like them. Typing bin/mygem still doesn’t satisfy me and prepending ./bin to my $PATH is too transparent. I prefer explicitly calling bundle exec only when I want.

That’s why I just use a good ol’ shell alias:

alias be="bundle exec "

<small>* Note the trailing space to trigger alias chaining.</small>

Then, I can call project-specific binaries by prepending be instead of bundle exec:

# before
bundle exec rails server

# after
be rails server

This is explicit, obvious, and short enough for my taste.

You might find other useful aliases in my dotfiles. Happy aliasing!

2 Responses
Add your response

Why not alias rails="bundle exec rails"?

over 1 year ago ·

Because rails is not the only command I want to execute in the Bundler context and I also want to be able to call rails outside the context of Bundler, eg. when initiating a new project: rails new project_name.

over 1 year ago ·