bundle exec fatigue
Tired of typing bundle exec rake? Me too. I even aliased it to bx, but that still breaks autocomplete and annoys me in subtle ways. So this week I finally remedied that situation, and thought I would share my setup since I haven’t seen anyone else with as nice of a setup.
First, bundler has a handy feature to install stubs for all of the bins in your gem dependencies.
$ bundle install --binstubs
This is great, but it creates them all in a bin directory in your project, so not only do you have to type `./bin/rake`, but you also have to ignore them from git. I’m lazy and that’s too much work!
The Final Solution
My bundler setup has 3 essential components: 1) an alias for bundle install which always installs bin stubs into .bin, 2) adding .bin to PATH, and 3) globally excluding the .bin directory from all git repos.
First, put the following in .bashrc, .profile, or .bash_profile to alias bundle install and add .bin to your PATH. :
alias bi="bundle install --binstubs=.bin" export PATH="./.bin:$PATH"
Now every time you run bi, it will install the gem dependencies and add the bin stubs in your path so you can just run rake like the good ol’ days. Now all you need to do is create a global ~/.gitignore that always excludes .bin from every project, and tell git to use it.
$ git config --global core.excludesfile ~/.gitignore
This approach has been working wonderfully for me. Now I just need to get out of the habit of typing bx.
Update: Travis Tilley pointed out rubygems-bundler in the comments. It looks like another unobtrusive (and more secure) way to accomplish this same thing.
10 Comments
This is an awesome fix, thanks a bunch.
Nice, thanks for tip!
Remind me to create hidden .bin directories all over the place containing scripts with common executable names. It certainly makes my life easier, as a traditional rootkit hunter would probably miss it, and checking binary integrity regularly with rpm —verify would too.
…I guess I’d really only need ~root/.bin/{cd,ls} or ~app_user/.bin/{cd,ls} depending on whether or not root privs are required to get the information I’m looking for. Possibly even just ~dev_user/.bin/{cd,ls} if I can get to everything else via your ssh keys and they don’t have a passphrase (i’m assuming they don’t to reduce typing).
For your own safety I would HIGHLY suggest removing your convenience PATH entry and instead using an .rvmrc file, which rvm will explicitly ask if you trust each time that file changes (and can contain arbitrary shell commands). As a playful aside, RVM actually overrides ‘cd’ in order to achieve the ability to have per-directory-tree aliases and settings.
Another option for getting rid of “bundle exec” is an extension to rubygems: https://github.com/mpapis/rubygems-bundler
It “makes executable wrappers generated by rubygems aware of bundler”. Behavior seems tweakable via environment variables.
Sorry for the harsh tone, just speaking as a sysadmin-turned-developer who’s had to de-fuck entirely too many client installs. ;)
As a bit more of an explanation, I meant those paths as persistent means of maintaining access, not obtaining it. Then again, I could also just ask you to take a look at something in my airdrop and immediately create those files.
Travis: I’m glad there are people in the world that care as much about security as you do, because I certainly don’t. I understand your point, but it’s my development machine, so I’m not too worried about it.
Thanks for pointing out gems-bundler. That looks like a great solution.
thanks for the link to rubygems-bundler.
the best solution would be to decouple bundler completely from rails, so that it is something you have to add in to your project if you want or need it’s functionality.
To go with what Travis had to say. Your prepending .bin to the start of your path. You should append it instead, like.
export PATH=“$PATH:./.bin”
This way /bin /usr/bin and your sbin directories, etc, are looked in first. That way someone can’t so easily stick a replacement for say su in .bin that installs a root kit or worse. This doesn’t really solve the problem, although it does help.
The only problem I noticed is that rvm prepends it’s bin to your PATH. I added the PATH setting after the rvm declaration and it seems to work.
Following up on my previous comment regarding rvm and the PATH. I needed to set my path within the rvm after_use hook here:
~/.rvm/hooks/after_use
You can achieve the same thing using `alias` only. You don’t need to install binstubs, another Gem or exclude .bin from your git repo. All these changes are fairly invasive.
Post a Comment