rbfu.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Enables rbfu with --auto option, if available.
  2. #
  3. # Also provides a command to list all installed/available
  4. # rubies. To ensure compatibility with themes, creates the
  5. # rvm_prompt_info function to return the $RBFU_RUBY_VERSION
  6. # version.
  7. command -v rbfu &>/dev/null
  8. if [[ $? -eq 0 ]]; then
  9. eval "$(rbfu --init --auto)"
  10. # Internal: Print ruby version details, if it's currently
  11. # active etc.
  12. function _rbfu_rubies_print() {
  13. local rb rb_out
  14. rb=$(basename $1)
  15. rb_out="$rb"
  16. [[ -h $1 ]] && rb_out="$rb_out${fg[green]}@${reset_color}"
  17. [[ "x$rb" == "x$2" ]] && rb_out="${fg[red]}$rb_out ${fg[red]}*${reset_color}"
  18. echo $rb_out
  19. }
  20. # Public: Provide a list with all available rubies, this basically depends
  21. # on `ls -1` and .rfbu/rubies. Highlights the currently active ruby version
  22. # and aliases.
  23. function rbfu-rubies() {
  24. local rbfu_dir active_rb
  25. rbfu_dir=$RBFU_RUBIES
  26. active_rb=$RBFU_RUBY_VERSION
  27. [[ -z "$rbfu_dir" ]] && rbfu_dir="${HOME}/.rbfu/rubies"
  28. [[ -z "$active_rb" ]] && active_rb="system"
  29. _rbfu_rubies_print "${rbfu_dir}/system" $active_rb
  30. for rb in $(ls -1 $rbfu_dir); do
  31. _rbfu_rubies_print "${rbfu_dir}/${rb}" $active_rb
  32. done
  33. }
  34. # Public: Create rvm_prompt_info command for themes compatibility, unless
  35. # it has already been defined.
  36. [ ! -x rvm_prompt_info ] && function rvm_prompt_info() { echo "${RBFU_RUBY_VERSION:=system}" }
  37. fi