Created
February 12, 2013 23:42
-
-
Save nyarly/4774570 to your computer and use it in GitHub Desktop.
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
| export PROMPT_DIRTRIM=2 | |
| if [[ ! $PROMPT_COMMAND =~ __bundler_prompt_command ]]; then | |
| export PROMPT_COMMAND="${PROMPT_COMMAND:-:} ; __bundler_prompt_command" | |
| fi | |
| # Put your fun stuff here. | |
| PS1='\[\033[01;31m\]$(__bundler_ps1)\[\033[00;34m\]\[\033[32m\]\u@\h\[\033[34m\] \w\[\033[01;32m\]$(__git_ps1) \[\033[34m\]\$\[\033[00m\] ' |
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 | |
| BUNDLE_BASE=~/ruby/bundle-paths/rails3 | |
| if [ -f .bundle/config ]; then | |
| echo "Bundle config file already exists" | |
| bundle install | |
| else | |
| projname=$(basename $(pwd)) | |
| BUNDLE_PATH="$BUNDLE_BASE/lib" | |
| BINSTUBS=".bundle/bin" | |
| echo "Setting up bundle for $projname" | |
| bundle install --path=$BUNDLE_PATH --binstubs=$BINSTUBS | |
| fi |
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
| export bundle_dir="" | |
| export bundle_bin="" | |
| export orig_path=$PATH | |
| function find_bundle_dir() { | |
| bundle_dir=$(pwd) | |
| while [ "$bundle_dir" != "/" ]; do | |
| if [ -e "$bundle_dir/.bundle/config" ]; then | |
| return 0 | |
| fi | |
| bundle_dir=$(dirname "$bundle_dir") | |
| done | |
| bundle_dir="" | |
| export bundle_dir | |
| return 1 | |
| } | |
| function bundle_config_changed() { | |
| local old_dir=$bundle_dir | |
| find_bundle_dir | |
| if [ "$bundle_dir" != "$old_dir" ]; then | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| function __bundler_prompt_command(){ | |
| if bundle_config_changed; then | |
| if [ ! -z "$bundle_bin" ]; then | |
| export PATH=$(echo $PATH | sed "s!${bundle_bin}\:!!") | |
| fi | |
| if [ -e "$bundle_dir/.bundle/config" ]; then | |
| export bundle_bin=$(readlink -f $(cat "$bundle_dir/.bundle/config" | grep BUNDLE_BIN | awk '{ print $2 }')) | |
| else | |
| export bundle_bin="" | |
| fi | |
| fi | |
| if echo $PATH | grep -q -v "$bundle_bin"; then | |
| export PATH=$bundle_bin:$PATH | |
| fi | |
| } | |
| function __bundler_ps1(){ | |
| if [ ! -z "$bundle_bin" ]; then | |
| if echo $PATH | grep -q "$bundle_bin"; then | |
| echo -n 'B ' | |
| fi | |
| fi | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Upshot here is: use bundle_setup (put in your PATH somewhere) in a new project with a Gemfile. It'll create binstubs for all the gems it installs.
The __bundler_prompt_command checks for a .bundle directory and uses it to modify your PATH so that those binstubs are available.
The PS1 (apart from naming the current git branch) adds a 'B' to the prompt when this setup is active, so you can be sure that things are running properly.
Upshot is that each project gets a gemset, reused gems are shared across projects (although it may be that that slows gem loading ... easy enough to change that behavior), and we're not adding another tool to the chain (i.e. rbenv/rvm)