Skip to content

Instantly share code, notes, and snippets.

@lsiden
Created January 8, 2012 06:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsiden/1577473 to your computer and use it in GitHub Desktop.
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
#!/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