prezto/modules/ruby/functions/ruby-info

35 lines
827 B
Text
Raw Normal View History

2012-09-06 23:06:50 -04:00
#
2012-09-06 23:17:38 -04:00
# Exposes information about the Ruby environment via the $ruby_info associative
# array.
2012-09-06 23:06:50 -04:00
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
local version
local version_format
local version_formatted
2015-02-27 01:25:19 -06:00
local version_manager
2012-09-06 23:06:50 -04:00
# Clean up previous $ruby_info.
unset ruby_info
typeset -gA ruby_info
if (( $+commands[rvm-prompt] )); then
version="$(rvm-prompt)"
2015-02-27 01:25:19 -06:00
version_manager="rvm"
2012-09-06 23:06:50 -04:00
elif (( $+commands[rbenv] )); then
version="$(rbenv version-name)"
2015-02-27 01:25:19 -06:00
version_manager="rbenv"
2014-02-01 23:37:29 -05:00
elif (( $+commands[ruby] )); then
version="${${$(ruby --version)[(w)1,(w)2]}/ /-}"
2015-02-27 01:25:19 -06:00
version_manager="ruby"
2012-09-06 23:06:50 -04:00
fi
# Format version.
if [[ -n "$version" ]]; then
2012-10-01 22:00:12 -04:00
zstyle -s ':prezto:module:ruby:info:version' format 'version_format'
2015-02-27 01:25:19 -06:00
zformat -a version_formatted ":" "$version_manager:$version"
2012-09-06 23:06:50 -04:00
ruby_info[version]="$version_formatted"
fi