mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-25 15:20:08 +00:00
rbenv: improve rbenv loading based on pyenv (#7626)
This commit is contained in:
parent
4cadbcd235
commit
20ecca2ba9
2 changed files with 46 additions and 41 deletions
|
@ -38,4 +38,4 @@ else
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset FOUND_PYENV dir
|
unset FOUND_PYENV pyenvdirs dir
|
||||||
|
|
|
@ -1,60 +1,65 @@
|
||||||
_homebrew-installed() {
|
# This plugin loads rbenv into the current shell and provides prompt info via
|
||||||
type brew &> /dev/null
|
# the 'rbenv_prompt_info' function.
|
||||||
}
|
|
||||||
|
|
||||||
FOUND_RBENV=0
|
FOUND_RBENV=$+commands[rbenv]
|
||||||
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
|
if [[ $FOUND_RBENV -ne 1 ]]; then
|
||||||
rbenvdirs=($rbenv_homebrew_path "${rbenvdirs[@]}")
|
rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" "/usr/local/opt/rbenv")
|
||||||
unset rbenv_homebrew_path
|
for dir in $rbenvdirs; do
|
||||||
if [[ $RBENV_ROOT = '' ]]; then
|
if [[ -d $dir/bin ]]; then
|
||||||
RBENV_ROOT="$HOME/.rbenv"
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for rbenvdir in "${rbenvdirs[@]}" ; do
|
if [[ $FOUND_RBENV -eq 1 ]]; then
|
||||||
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
|
|
||||||
eval "$(rbenv init --no-rehash - zsh)"
|
eval "$(rbenv init --no-rehash - zsh)"
|
||||||
|
|
||||||
alias rubies="rbenv versions"
|
alias rubies="rbenv versions"
|
||||||
alias gemsets="rbenv gemset list"
|
alias gemsets="rbenv gemset list"
|
||||||
|
|
||||||
function current_ruby() {
|
function current_ruby() {
|
||||||
echo "$(rbenv version-name)"
|
echo "$(rbenv version-name)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function current_gemset() {
|
function current_gemset() {
|
||||||
echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)"
|
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)
|
local rbenv_path=$(rbenv prefix)
|
||||||
gem list $@ | sed -E \
|
gem list $@ | sed -E \
|
||||||
-e "s/\([0-9a-z, \.]+( .+)?\)/$fg[blue]&$reset_color/g" \
|
-e "s/\([0-9a-z, \.]+( .+)?\)/$fg[blue]&$reset_color/g" \
|
||||||
-e "s|$(echo $rbenv_path)|$fg[magenta]\$rbenv_path$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@global/$fg[yellow]&$reset_color/g" \
|
||||||
-e "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
|
-e "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
|
||||||
}
|
}
|
||||||
|
|
||||||
function rbenv_prompt_info() {
|
function rbenv_prompt_info() {
|
||||||
if [[ -n $(current_gemset) ]] ; then
|
if [[ -n $(current_gemset) ]] ; then
|
||||||
echo "$(current_ruby)@$(current_gemset)"
|
echo "$(current_ruby)@$(current_gemset)"
|
||||||
else
|
else
|
||||||
echo "$(current_ruby)"
|
echo "$(current_ruby)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
fi
|
else
|
||||||
done
|
alias rubies="ruby -v"
|
||||||
unset rbenvdir
|
function gemsets() { echo "not supported" }
|
||||||
|
function current_ruby() { echo "not supported" }
|
||||||
if [ $FOUND_RBENV -eq 0 ] ; then
|
function current_gemset() { echo "not supported" }
|
||||||
alias rubies='ruby -v'
|
function gems() { echo "not supported" }
|
||||||
function gemsets() { echo 'not supported' }
|
function rbenv_prompt_info() { echo "system: $(ruby -v | cut -f-2 -d ' ')" }
|
||||||
function rbenv_prompt_info() { echo "system: $(ruby -v | cut -f-2 -d ' ')" }
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
unset FOUND_RBENV rbenvdirs dir
|
||||||
|
|
Loading…
Reference in a new issue