1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-22 05:40:08 +00:00

rbenv: improve rbenv loading based on pyenv (#7626)

This commit is contained in:
Thomas Kriechbaumer 2019-05-08 09:51:05 +02:00 committed by Marc Cornellà
parent 4cadbcd235
commit 20ecca2ba9
2 changed files with 46 additions and 41 deletions

View file

@ -38,4 +38,4 @@ else
}
fi
unset FOUND_PYENV dir
unset FOUND_PYENV pyenvdirs dir

View file

@ -1,25 +1,29 @@
_homebrew-installed() {
type brew &> /dev/null
}
# This plugin loads rbenv into the current shell and provides prompt info via
# the 'rbenv_prompt_info' function.
FOUND_RBENV=0
rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" "/usr/local/opt/rbenv")
if _homebrew-installed && rbenv_homebrew_path=$(brew --prefix rbenv 2>/dev/null); then
rbenvdirs=($rbenv_homebrew_path "${rbenvdirs[@]}")
unset rbenv_homebrew_path
if [[ $RBENV_ROOT = '' ]]; then
RBENV_ROOT="$HOME/.rbenv"
FOUND_RBENV=$+commands[rbenv]
if [[ $FOUND_RBENV -ne 1 ]]; then
rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" "/usr/local/opt/rbenv")
for dir in $rbenvdirs; do
if [[ -d $dir/bin ]]; then
export PATH="$dir/bin:$PATH"
FOUND_RBENV=1
break
fi
done
fi
if [[ $FOUND_RBENV -ne 1 ]]; then
if (( $+commands[brew] )) && dir=$(brew --prefix rbenv 2>/dev/null); then
if [[ -d $dir/bin ]]; then
export PATH="$dir/bin:$PATH"
FOUND_RBENV=1
fi
fi
fi
for rbenvdir in "${rbenvdirs[@]}" ; do
if [ -d $rbenvdir/bin -a $FOUND_RBENV -eq 0 ] ; then
FOUND_RBENV=1
if [[ $RBENV_ROOT = '' ]]; then
RBENV_ROOT=$rbenvdir
fi
export RBENV_ROOT
export PATH=${rbenvdir}/bin:$PATH
if [[ $FOUND_RBENV -eq 1 ]]; then
eval "$(rbenv init --no-rehash - zsh)"
alias rubies="rbenv versions"
@ -33,7 +37,7 @@ for rbenvdir in "${rbenvdirs[@]}" ; do
echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)"
}
function gems {
function gems() {
local rbenv_path=$(rbenv prefix)
gem list $@ | sed -E \
-e "s/\([0-9a-z, \.]+( .+)?\)/$fg[blue]&$reset_color/g" \
@ -49,12 +53,13 @@ for rbenvdir in "${rbenvdirs[@]}" ; do
echo "$(current_ruby)"
fi
}
fi
done
unset rbenvdir
if [ $FOUND_RBENV -eq 0 ] ; then
alias rubies='ruby -v'
function gemsets() { echo 'not supported' }
else
alias rubies="ruby -v"
function gemsets() { echo "not supported" }
function current_ruby() { echo "not supported" }
function current_gemset() { echo "not supported" }
function gems() { echo "not supported" }
function rbenv_prompt_info() { echo "system: $(ruby -v | cut -f-2 -d ' ')" }
fi
unset FOUND_RBENV rbenvdirs dir