Created
May 28, 2013 10:11
-
-
Save mpasternacki/5661786 to your computer and use it in GitHub Desktop.
Script to activate Ruby Gem Bundler environment in current shell session.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# This script activates a Gem Bundler environment in current shell | |
# session. This lets you type commands without `bundle exec` all the | |
# time, even if you leave the project's directory, and without complex | |
# magic that runs with every command. | |
# | |
# Usage: save this file somewhere. Use following command to activate | |
# current directory's bundle in current shell session: | |
# | |
# eval `/path/to/bundle-activate` | |
# | |
# For convenience you may add alias to your shell's initialization | |
# file (e.g. ~/.profile): | |
# | |
# alias ba='eval `path/to/bundle-activate`' | |
# | |
set -e | |
old=`mktemp env.unbundled.XXXXX` | |
new=`mktemp env.bundled.XXXXX` | |
out=`mktemp env.changed.XXXXX` | |
env > $old | |
bundle exec env > $new | |
fgrep -v -f $old $new \ | |
| grep -v '^_=' \ | |
| sed "s/'/'\\\\''/g; s/^/'/; s/$/'/" \ | |
> $out | |
prj="`grep '^BUNDLE_GEMFILE=' $new | cut -d= -f2-`" | |
prj="`dirname $prj`" | |
prj="`basename $prj`" | |
echo "PS1=\"(bundle@$prj)\$PS1\"" >> $out | |
tr \\n \\0 < $out | xargs -0 echo export | |
rm $old $new $out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment