rbenv.plugin.zsh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. FOUND_RBENV=0
  2. for rbenvdir in "$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" ; do
  3. if [ -d $rbenvdir/bin -a $FOUND_RBENV -eq 0 ] ; then
  4. FOUND_RBENV=1
  5. export RBENV_ROOT=$rbenvdir
  6. export PATH=${rbenvdir}/bin:$PATH
  7. eval "$(rbenv init -)"
  8. alias rubies="rbenv versions"
  9. alias gemsets="rbenv gemset list"
  10. function current_ruby() {
  11. echo "$(rbenv version-name)"
  12. }
  13. function current_gemset() {
  14. echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)"
  15. }
  16. function gems {
  17. local rbenv_path=$(rbenv prefix)
  18. gem list $@ | sed \
  19. -Ee "s/\([0-9\.]+( .+)?\)/$fg[blue]&$reset_color/g" \
  20. -Ee "s|$(echo $rbenv_path)|$fg[magenta]\$rbenv_path$reset_color|g" \
  21. -Ee "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \
  22. -Ee "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
  23. }
  24. function rbenv_prompt_info() {
  25. if [[ -n $(current_gemset) ]] ; then
  26. echo "$(current_ruby)@$(current_gemset)"
  27. else
  28. echo "$(current_ruby)"
  29. fi
  30. }
  31. fi
  32. done
  33. unset rbenvdir
  34. if [ $FOUND_RBENV -eq 0 ] ; then
  35. alias rubies='ruby -v'
  36. function gemsets() { echo 'not supported' }
  37. function rbenv_prompt_info() { echo "system: $(ruby -v | cut -f-2 -d ' ')" }
  38. fi