ruby-info 897 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #
  2. # Exposes information about the Ruby environment via the $ruby_info associative
  3. # array.
  4. #
  5. # Authors:
  6. # Sorin Ionescu <sorin.ionescu@gmail.com>
  7. #
  8. # function ruby-info {
  9. local version
  10. local version_format
  11. local version_formatted
  12. # Clean up previous $ruby_info.
  13. unset ruby_info
  14. typeset -gA ruby_info
  15. # Grab formatting for anything we might have to do
  16. zstyle -s ':prezto:module:ruby:info:version' format 'version_format'
  17. if [[ -n "$version_format" ]]; then
  18. if (( $+commands[rvm-prompt] )); then
  19. version="$(rvm-prompt)"
  20. elif (( $+commands[rbenv] )); then
  21. version="$(rbenv version-name)"
  22. elif (( $+commands[ruby] )); then
  23. version="${${$(ruby --version)[(w)1,(w)2]}/ /-}"
  24. fi
  25. # Format version.
  26. if [[ -n "$version" && "$version" != "system" ]]; then
  27. zformat -f version_formatted "$version_format" "v:$version"
  28. ruby_info[version]="$version_formatted"
  29. fi
  30. fi
  31. # }