2019-05-08 09:51:05 +02:00
|
|
|
# This plugin loads rbenv into the current shell and provides prompt info via
|
|
|
|
# the 'rbenv_prompt_info' function.
|
|
|
|
|
|
|
|
FOUND_RBENV=$+commands[rbenv]
|
|
|
|
|
|
|
|
if [[ $FOUND_RBENV -ne 1 ]]; then
|
2021-12-13 17:42:17 +01:00
|
|
|
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
|
2012-06-18 19:15:57 +02:00
|
|
|
fi
|
|
|
|
|
2019-05-08 09:51:05 +02:00
|
|
|
if [[ $FOUND_RBENV -ne 1 ]]; then
|
2021-12-13 17:42:17 +01:00
|
|
|
if (( $+commands[brew] )) && dir=$(brew --prefix rbenv 2>/dev/null); then
|
|
|
|
if [[ -d $dir/bin ]]; then
|
|
|
|
export PATH="$dir/bin:$PATH"
|
|
|
|
FOUND_RBENV=1
|
2013-10-14 17:59:20 +02:00
|
|
|
fi
|
2021-12-13 17:42:17 +01:00
|
|
|
fi
|
2019-05-08 09:51:05 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $FOUND_RBENV -eq 1 ]]; then
|
2021-12-13 17:42:17 +01:00
|
|
|
eval "$(rbenv init --no-rehash - zsh)"
|
2011-10-20 08:12:56 +02:00
|
|
|
|
2021-12-13 17:42:17 +01:00
|
|
|
alias rubies="rbenv versions"
|
|
|
|
alias gemsets="rbenv gemset list"
|
2011-10-20 08:12:56 +02:00
|
|
|
|
2021-12-13 17:42:17 +01:00
|
|
|
function current_ruby() {
|
|
|
|
echo "$(rbenv version-name)"
|
|
|
|
}
|
2011-10-20 08:12:56 +02:00
|
|
|
|
2021-12-13 17:42:17 +01:00
|
|
|
function current_gemset() {
|
|
|
|
echo "$(rbenv gemset active 2>/dev/null)" | tr ' ' '+'
|
|
|
|
}
|
2011-10-20 08:12:56 +02:00
|
|
|
|
2021-12-13 17:42:17 +01:00
|
|
|
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"
|
|
|
|
}
|
2011-10-20 08:12:56 +02:00
|
|
|
|
2021-12-13 17:42:17 +01:00
|
|
|
function rbenv_prompt_info() {
|
|
|
|
local ruby=$(current_ruby) gemset=$(current_gemset)
|
|
|
|
echo -n "${ZSH_THEME_RUBY_PROMPT_PREFIX}"
|
|
|
|
[[ -n "$gemset" ]] && echo -n "${ruby}@${gemset}" || echo -n "${ruby}"
|
|
|
|
echo "${ZSH_THEME_RUBY_PROMPT_SUFFIX}"
|
|
|
|
}
|
2019-05-08 09:51:05 +02:00
|
|
|
else
|
2021-12-13 17:42:17 +01:00
|
|
|
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 -n "${ZSH_THEME_RUBY_PROMPT_PREFIX}"
|
|
|
|
echo -n "system: $(ruby -v | cut -f-2 -d ' ')"
|
|
|
|
echo "${ZSH_THEME_RUBY_PROMPT_SUFFIX}"
|
|
|
|
}
|
2011-10-20 08:12:56 +02:00
|
|
|
fi
|
2019-05-08 09:51:05 +02:00
|
|
|
|
|
|
|
unset FOUND_RBENV rbenvdirs dir
|