mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-03-27 03:14:56 +01:00
When using system-wide rbenv (as in provided by vendor packages like in Ubuntu or FreeBSD), PATH is not set to the correct ruby binary. This leads to being unable to use rubies installed with rbenv (and stick with the system-wide ruby installed, if any). This patch correct this behaviour, setting the correct PATH.
57 lines
1.6 KiB
Bash
57 lines
1.6 KiB
Bash
_homebrew-installed() {
|
|
type brew &> /dev/null
|
|
}
|
|
|
|
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
|
|
fi
|
|
|
|
for rbenvdir in "${rbenvdirs[@]}" ; do
|
|
if [ -d $rbenvdir -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
|
|
eval "$(rbenv init --no-rehash - zsh)"
|
|
|
|
alias rubies="rbenv versions"
|
|
alias gemsets="rbenv gemset list"
|
|
|
|
function current_ruby() {
|
|
echo "$(rbenv version-name)"
|
|
}
|
|
|
|
function current_gemset() {
|
|
echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)"
|
|
}
|
|
|
|
function gems {
|
|
local rbenv_path=$(rbenv prefix)
|
|
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"
|
|
}
|
|
|
|
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
|