2012-06-18 19:15:57 +02:00
|
|
|
function is_homebrew_installed() {
|
|
|
|
type brew &> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_rbenv_installed() {
|
|
|
|
brew --prefix rbenv &> /dev/null
|
|
|
|
}
|
|
|
|
|
2011-10-20 08:12:56 +02:00
|
|
|
FOUND_RBENV=0
|
2012-06-18 19:15:57 +02:00
|
|
|
rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv")
|
|
|
|
if is_homebrew_installed && is_rbenv_installed ; then
|
|
|
|
rbenvdirs=($(brew --prefix rbenv) "${rbenvdirs[@]}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
for rbenvdir in "${rbenvdirs[@]}" ; do
|
2011-10-20 08:12:56 +02:00
|
|
|
if [ -d $rbenvdir/bin -a $FOUND_RBENV -eq 0 ] ; then
|
|
|
|
FOUND_RBENV=1
|
|
|
|
export RBENV_ROOT=$rbenvdir
|
|
|
|
export PATH=${rbenvdir}/bin:$PATH
|
|
|
|
eval "$(rbenv init -)"
|
|
|
|
|
|
|
|
alias rubies="rbenv versions"
|
|
|
|
alias gemsets="rbenv gemset list"
|
|
|
|
|
|
|
|
function current_ruby() {
|
|
|
|
echo "$(rbenv version-name)"
|
|
|
|
}
|
|
|
|
|
|
|
|
function current_gemset() {
|
2011-10-20 09:27:49 +02:00
|
|
|
echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)"
|
2011-10-20 08:12:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function gems {
|
|
|
|
local rbenv_path=$(rbenv prefix)
|
|
|
|
gem list $@ | sed \
|
|
|
|
-Ee "s/\([0-9\.]+( .+)?\)/$fg[blue]&$reset_color/g" \
|
|
|
|
-Ee "s|$(echo $rbenv_path)|$fg[magenta]\$rbenv_path$reset_color|g" \
|
|
|
|
-Ee "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \
|
|
|
|
-Ee "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
|
|
|
|
}
|
|
|
|
|
|
|
|
function rbenv_prompt_info() {
|
|
|
|
if [[ -n $(current_gemset) ]] ; then
|
|
|
|
echo "$(current_ruby)@$(current_gemset)"
|
|
|
|
else
|
|
|
|
echo "$(current_ruby)"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset rbenvdir
|
|
|
|
|
|
|
|
if [ $FOUND_RBENV -eq 0 ] ; then
|
|
|
|
alias rubies='ruby -v'
|
|
|
|
function gemsets() { echo 'not supported' }
|
|
|
|
function rbenv_prompt_info() { echo "system: $(ruby -v | cut -f-2 -d ' ')" }
|
|
|
|
fi
|