Skip to content

Commit

Permalink
[Fix sorin-ionescu#259] Add ruby-info function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorin Ionescu committed Sep 7, 2012
1 parent 5542164 commit a151bc9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modules/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
28 changes: 28 additions & 0 deletions modules/ruby/functions/ruby-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Displays Ruby information.
#
# Authors:
# Sorin Ionescu <[email protected]>
#

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

0 comments on commit a151bc9

Please sign in to comment.