2012-06-18 18:29:24 +00:00
|
|
|
_homebrew-installed() {
|
2012-06-18 17:15:57 +00:00
|
|
|
type brew &> /dev/null
|
|
|
|
}
|
|
|
|
|
2012-06-18 18:29:24 +00:00
|
|
|
_rbenv-from-homebrew-installed() {
|
2012-06-18 17:15:57 +00:00
|
|
|
brew --prefix rbenv &> /dev/null
|
|
|
|
}
|
|
|
|
|
2011-10-20 06:12:56 +00:00
|
|
|
FOUND_RBENV=0
|
2013-01-14 09:46:01 +00:00
|
|
|
rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" "/usr/local/opt/rbenv")
|
2012-06-18 18:29:24 +00:00
|
|
|
if _homebrew-installed && _rbenv-from-homebrew-installed ; then
|
2012-06-18 17:15:57 +00:00
|
|
|
rbenvdirs=($(brew --prefix rbenv) "${rbenvdirs[@]}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
for rbenvdir in "${rbenvdirs[@]}" ; do
|
2011-10-20 06:12:56 +00:00
|
|
|
if [ -d $rbenvdir/bin -a $FOUND_RBENV -eq 0 ] ; then
|
|
|
|
FOUND_RBENV=1
|
2013-10-14 15:59:20 +00:00
|
|
|
if [[ $RBENV_ROOT = '' ]]; then
|
|
|
|
RBENV_ROOT=$rbenvdir
|
|
|
|
fi
|
|
|
|
export RBENV_ROOT
|
2011-10-20 06:12:56 +00:00
|
|
|
export PATH=${rbenvdir}/bin:$PATH
|
2013-03-20 15:57:32 +00:00
|
|
|
eval "$(rbenv init --no-rehash - zsh)"
|
2011-10-20 06:12:56 +00:00
|
|
|
|
|
|
|
alias rubies="rbenv versions"
|
|
|
|
alias gemsets="rbenv gemset list"
|
|
|
|
|
|
|
|
function current_ruby() {
|
|
|
|
echo "$(rbenv version-name)"
|
|
|
|
}
|
|
|
|
|
|
|
|
function current_gemset() {
|
2011-10-20 07:27:49 +00:00
|
|
|
echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)"
|
2011-10-20 06:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function gems {
|
|
|
|
local rbenv_path=$(rbenv prefix)
|
2013-02-09 02:11:40 +00:00
|
|
|
gem list $@ | sed -E \
|
|
|
|
-e "s/\([0-9a-z, \.]+( .+)?\)/$fg[blue]&$reset_color/g" \
|
|
|
|
-e "s|$(echo $rbenv_path)|$fg[magenta]\$rbenv_path$reset_color|g" \
|
|
|
|
-e "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \
|
|
|
|
-e "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
|
2011-10-20 06:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|