From e5a9bdc4b4b8332e13cf02d5d5ef368de131f9b5 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Thu, 6 Sep 2012 23:06:50 -0400 Subject: [PATCH] [Fix #259] Add ruby-info function --- modules/ruby/README.md | 18 ++++++++++++++++++ modules/ruby/functions/ruby-info | 28 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 modules/ruby/functions/ruby-info diff --git a/modules/ruby/README.md b/modules/ruby/README.md index 984b1a1..a95bc36 100644 --- a/modules/ruby/README.md +++ b/modules/ruby/README.md @@ -56,6 +56,24 @@ Aliases - `rbbp` packages gem files into *vendor/cache*. - `rbbu` updates gems to their latest version. +Functions +--------- + + - `ruby-info` exposes information about the Ruby environment via the + `$ruby_info` associative array. + +Theming +------- + +To display the name of the current Ruby version in a prompt, define the +following style in the `prompt_theme_setup` function. + + # %v - ruby version. + zstyle ':prezto:module:ruby' version 'version:%v' + +Then add `$ruby_info[version]` to `$PROMPT` or `$RPROMPT` and call +`ruby-info` in the `prompt_theme_preexec` hook function. + Authors ------- diff --git a/modules/ruby/functions/ruby-info b/modules/ruby/functions/ruby-info new file mode 100644 index 0000000..21dc1d6 --- /dev/null +++ b/modules/ruby/functions/ruby-info @@ -0,0 +1,28 @@ +# +# Displays Ruby information. +# +# Authors: +# Sorin Ionescu +# + +local version +local version_format +local version_formatted + +# Clean up previous $ruby_info. +unset ruby_info +typeset -gA ruby_info + +if (( $+commands[rvm-prompt] )); then + version="$(rvm-prompt)" +elif (( $+commands[rbenv] )); then + version="$(rbenv version-name)" +fi + +# Format version. +if [[ -n "$version" ]]; then + zstyle -s ':prezto:module:ruby' version 'version_format' + zformat -f version_formatted "$version_format" "v:$version" + ruby_info[version]="$version_formatted" +fi +