public
Created

Wrapper for rvm-prompt that searches parent directories for files that tell we're in a Ruby project dir or sub-dir

  • Download Gist
my-rvm-prompt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 
#!/bin/bash
 
# Use this script instead of ~/.rvm/bin/rvm-prompt
# and the output of rvm-prompt will show up in your command prompt
# only if you are in a Ruby project directory.
 
# see http://stackoverflow.com/a/4264351/270511
# and http://unix.stackexchange.com/questions/13464/is-there-a-way-to-find-a-file-in-an-inverse-recursive-search
 
upsearch () {
the_test=$1
up_to=$2
curdir=`pwd`
result=1
 
while [[ "`pwd`" != "$up_to" && "`pwd`" != '/' ]]; do
if eval "[[ $the_test ]]"; then
result=0
break
fi
cd ..
done
cd $curdir
return $result
}
 
if upsearch '-e Gemfile || ! -z "$(shopt -s nullglob; echo *.gemspec *.rb)"' ; then
~/.rvm/bin/rvm-prompt
fi

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.