conf2/zsh/.oh-my-zsh/plugins/rbenv/rbenv.plugin.zsh

66 lines
1.9 KiB
Bash
Raw Normal View History

2019-10-24 19:09:05 +00: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
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
2019-01-12 15:47:23 +00:00
fi
2019-10-24 19:09:05 +00:00
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
2019-01-12 15:47:23 +00:00
fi
2019-10-24 19:09:05 +00:00
fi
if [[ $FOUND_RBENV -eq 1 ]]; then
2019-01-12 15:47:23 +00:00
eval "$(rbenv init --no-rehash - zsh)"
alias rubies="rbenv versions"
alias gemsets="rbenv gemset list"
function current_ruby() {
2019-10-24 19:09:05 +00:00
echo "$(rbenv version-name)"
2019-01-12 15:47:23 +00:00
}
function current_gemset() {
echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)"
2019-01-12 15:47:23 +00:00
}
2019-10-24 19:09:05 +00: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"
2019-01-12 15:47:23 +00:00
}
function rbenv_prompt_info() {
if [[ -n $(current_gemset) ]] ; then
echo "$(current_ruby)@$(current_gemset)"
else
echo "$(current_ruby)"
fi
2019-01-12 15:47:23 +00:00
}
2019-10-24 19:09:05 +00:00
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 ' ')" }
2019-01-12 15:47:23 +00:00
fi
2019-10-24 19:09:05 +00:00
unset FOUND_RBENV rbenvdirs dir