Created
October 15, 2011 20:31
-
-
Save nyarly/1290098 to your computer and use it in GitHub Desktop.
Change PATH based on Gemfile
This file contains 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
source "/home/judson/bin/bundler_ps1.sh" | |
if [[ ! $PROMPT_COMMAND =~ __bundler_prompt_command ]]; then | |
export PROMPT_COMMAND="${PROMPT_COMMAND:-:} ; __bundler_prompt_command" | |
fi | |
PS1="\[\033[01;31m\]\$(__bundler_ps1)\[\033[01;34m\] $PS1" |
This file contains 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/ | |
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 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 | |
echo $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=$(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 | |
} |
This file contains 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
judson@dijkstra /home/judson $ echo $PATH | |
~/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3:/usr/games/bin | |
judson@dijkstra /home/judson $ cd ruby/gems/vizier/ | |
B judson@dijkstra .../gems/vizier $ echo $PATH | |
/home/judson/ruby/bundle-paths/vizier/bin:~/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3:/usr/games/bin | |
B judson@dijkstra .../gems/vizier $ cd ../../LRD/ecliptic/ | |
B judson@dijkstra .../LRD/ecliptic (master) $ echo $PATH | |
/home/judson/ruby/bundle-paths/ecliptic/bin:~/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3:/usr/games/bin | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The update looks great. I had not thought about other command_prompt tools. Though, I have an idea for one myself ;-)
I am so busy that I will not have time to try this out until the weekend. But I am definitely going to give a shot.
Again on the off topic system versus bundler gems. I suppose sometimes the designers are too close to their projects to explain the BIG picture to neophytes like myself, but I could not really get the idea that I had to use rails to make a rails project. Meaning that there are two levels of usage - it is a tool and "library". This became very confusing for me once I had more that one version of rails on my system. And I could not really find a doc or tutorial that clearly explained this -- and I have read a lot of them
I only just found out how to select which version of a system gem to run from the command line by passing its version number quoted by underscores. IOW, if I have rails 3.2.2, 3.1.11 and 2.3.5 installed as system gems I can build a new rails 2.3.5 project using:
OR a rails 3.1.11project using:
and plain:
gets me a 3.2.2 project.
The irony is that I cannot find blurb where I read this again! I really do not want to test it until I can find some real documentation on it -- oh well, sorry for the side track...
Anyway I will let you know how it goes with your code next week. Thanks for implementing a great idea!