123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #!/usr/bin/env bash
- add()
- {
- token=${1:-""}
- eval "${token}_flag=1"
- shift
- if
- [[ -n "$format" ]]
- then
- [[ ${previous_is_format_var:-0} == 1 ]] && eval "${token}_prefix_flag=1"
- format="${format}\$${token}"
- else
- format="\$${token}"
- fi
- previous_is_format_var=1
- }
- add_raw_token()
- {
- previous_is_format_var=0
- token=${1:-""}
- format="${format:-""}${token}"
- }
- rvm_gemset_separator="${rvm_gemset_separator:-"@"}"
- if
- [[ "${GEM_HOME:-}" == *rvm* && "$ruby_string" != "$rvm_path/bin/ruby" ]]
- then
- unset format
- while
- (( $# ))
- do
- case "$1" in
- i|interpreter) add "interpreter" ;;
- v|version) add "version" ;;
- p|patchlevel) add "patchlevel" ;;
- r|revision) add "revision" ;;
- a|architecture) add "architecture" ;;
- g|gemset) add "gemset" ;;
- u|unicode) add "unicode" ;;
- s|system) ;; #skip when in ruby
- -d|--no-default) no_default=1 ;;
- *) add_raw_token "$1" ;;
- esac
- shift
- done
- if
- [[ -z "${format:-""}" && -z "$no_default" ]]
- then
- for default in interpreter version patchlevel gemset
- do
- add "$default"
- done
- fi
- gemset=""
- ruby_string="${GEM_HOME:-""}"
- ruby_string="${ruby_string##*/}"
- case "${GEM_HOME:-""}" in
- (*${rvm_gemset_separator:-"@"}*)
- if (( ${gemset_flag:-0} ))
- then gemset="${rvm_gemset_separator:-"@"}${ruby_string##*${rvm_gemset_separator:-"@"}}"
- fi
- ruby_string="${ruby_string%%${rvm_gemset_separator:-"@"}*}"
- ;;
- esac
- if
- [[ -n "$no_default" && -n "${format:-""}" ]]
- then
- # Do not display anything if no default flag was provided
- # and we are using the default ruby
- # Only people who explicitly ask for this will have the
- # slight performance penalty associated.
- [[ "$(rvm tools identifier)" != "$(rvm alias show default)" ]] || exit 0
- fi
- strings=(${ruby_string//-/ })
- if
- (( ${interpreter_flag:-0} )) || [[ -n "$unicode_flag" ]]
- then
- interpreter=${strings[0]}
- (( ${interpreter_prefix_flag:-0} )) && interpreter="-${interpreter}"
- fi
- if
- (( ${version_flag:-0} )) || [[ -n "$unicode_flag" ]]
- then
- version=${strings[1]}
- (( ${version_prefix_flag:-0} )) && version="-${version}"
- fi
- if
- (( ${#strings[@]} > 2 ))
- then
- if
- (( ${patchlevel_flag:-0} ))
- then
- patchlevel=${strings[2]}
- (( ${patchlevel_prefix_flag:-0} )) && patchlevel="-${patchlevel}"
- fi
- fi
- if
- (( ${architecture_flag:-0} ))
- then
- architecture="$(echo "$(ruby -v)" | sed 's/^.*\[//' | sed 's/\].*$//')"
- (( ${architecture_prefix_flag:-0} )) && architecture="-${architecture}"
- fi
- if
- (( ${unicode_flag:-0} ))
- then
- case "$interpreter" in
- (jruby) unicode="☯" ;;
- (rbx) unicode="❖" ;;
- (ree) unicode="✈" ;;
- (macruby) unicode="⌘" ;;
- (maglev) unicode="㎖" ;;
- (ironruby) unicode="♭" ;;
- (system) unicode="★" ;;
- (topaz) unicode="🐍" ;; # TODO: what is this? can we use something more fonts support?
- (truffleruby) unicode="🚀" ;;
- (opal) unicode="⬢" ;;
- (ruby)
- case ${version:-""} in
- (1.8.6) unicode="➇❻" ;;
- (1.8.7) unicode="➇❼" ;;
- (1.8*) unicode="➇" ;;
- (1.9.1) unicode="➈❶" ;;
- (1.9.2) unicode="➈❷" ;;
- (1.9.3) unicode="➈❸" ;;
- (2.0.0) unicode="➋" ;;
- (2.1.*) unicode="➋➀" ;;
- (2.2.*) unicode="➋➁" ;;
- (2.3.*) unicode="➋➂" ;;
- (2.4.*) unicode="➋➃" ;;
- (*) unicode="⦿" ;;
- esac ;;
- (*) unicode="⦿" ;;
- esac
- if
- echo "$ruby_string" | GREP_OPTIONS="" \grep '-head' >/dev/null 2>&1
- then
- unicode="${unicode}⚡"
- fi
- (( ${unicode_prefix_flag:-0} )) && unicode="-${unicode}"
- fi
- eval "echo \"$format\""
- else
- while
- (( $# ))
- do
- case "$1" in
- s|system) echo "system" ;;
- esac
- shift
- done
- fi
|