summaryrefslogtreecommitdiff
path: root/plugins/rbenv
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/rbenv')
-rw-r--r--plugins/rbenv/README.md26
-rw-r--r--plugins/rbenv/rbenv.plugin.zsh87
2 files changed, 72 insertions, 41 deletions
diff --git a/plugins/rbenv/README.md b/plugins/rbenv/README.md
new file mode 100644
index 000000000..43a2e93ac
--- /dev/null
+++ b/plugins/rbenv/README.md
@@ -0,0 +1,26 @@
+# rbenv plugin
+
+The primary job of this plugin is to provide `rbenv_prompt_info` which can be added to your theme to include Ruby
+version and gemset information into your prompt.
+
+Some functionality of this plugin will not work unless you also have the rbenv plugin *gemset* installed.
+https://github.com/jf/rbenv-gemset
+
+To use it, add `rbenv` to the plugins array in your zshrc file:
+```zsh
+plugins=(... rbenv)
+```
+
+## Alias
+
+| Alias | Command | Description |
+|----------------|---------------------|----------------------------------|
+| rubies | `rbenv versions` | List the installed Ruby versions |
+| gemsets | `rbenv gemset list` | List the existing gemsets |
+
+## Functions
+
+* `current_ruby`: The version of Ruby currently being used.
+* `current_gemset`: The name of the current gemset.
+* `gems`: Lists installed gems with enhanced formatting and color.
+* `rbenv_prompt_info`: For adding information to your prompt. Format: `<ruby version>@<current gemset>`.
diff --git a/plugins/rbenv/rbenv.plugin.zsh b/plugins/rbenv/rbenv.plugin.zsh
index 213e1beb0..ed46d355b 100644
--- a/plugins/rbenv/rbenv.plugin.zsh
+++ b/plugins/rbenv/rbenv.plugin.zsh
@@ -1,60 +1,65 @@
-_homebrew-installed() {
- type brew &> /dev/null
-}
-
-_rbenv-from-homebrew-installed() {
- brew --prefix rbenv &> /dev/null
-}
-
-FOUND_RBENV=0
-rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" "/usr/local/opt/rbenv")
-if _homebrew-installed && _rbenv-from-homebrew-installed ; then
- rbenvdirs=($(brew --prefix rbenv) "${rbenvdirs[@]}")
+# 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
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
+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
- export RBENV_ROOT
- export PATH=${rbenvdir}/bin:$PATH
+fi
+
+if [[ $FOUND_RBENV -eq 1 ]]; then
eval "$(rbenv init --no-rehash - zsh)"
alias rubies="rbenv versions"
alias gemsets="rbenv gemset list"
function current_ruby() {
- echo "$(rbenv version-name)"
+ 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)"
+ 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 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
+ 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 ' ')" }
+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