Created
January 8, 2012 06:28
-
-
Save lsiden/1577473 to your computer and use it in GitHub Desktop.
Wrapper for rvm-prompt that searches parent directories for files that tell we're in a Ruby project dir or sub-dir
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/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment