Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 152 lines (147 sloc) 3.816 kb
7bff3d4 @wayneeseguin Switched shebang lines to use /usr/bin/env.
authored
1 #!/usr/bin/env bash
b86c5ed @wayneeseguin rvm-prompt has been rewritten to be flexible.
authored
2
6976a01 @wayneeseguin Slight refactoring in rvm-prompt.
authored
3 add()
4 {
5f8cfc5 @wayneeseguin Removing usages of =~ so as to not be "idiotic", by the power of GreyCat...
authored
5 token=${1:-""}
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
6 eval "${token}_flag=1"
7 shift
8 if
9 [[ -n "$format" ]]
10 then
3329fc8 @mpapis fix = to == - for #475
mpapis authored
11 [[ ${previous_is_format_var:-0} == 1 ]] && eval "${token}_prefix_flag=1"
2abdd30 @griff Restructured how the - separator gets inserted in rvm-prompt to remove t...
griff authored
12 format="${format}\$${token}"
b86c5ed @wayneeseguin rvm-prompt has been rewritten to be flexible.
authored
13 else
14 format="\$${token}"
15 fi
6cbadc1 @noplay Allow to use characters in prompt like virtualenv for python
noplay authored
16 previous_is_format_var=1
17 }
18
6976a01 @wayneeseguin Slight refactoring in rvm-prompt.
authored
19 add_raw_token()
20 {
6cbadc1 @noplay Allow to use characters in prompt like virtualenv for python
noplay authored
21 previous_is_format_var=0
6976a01 @wayneeseguin Slight refactoring in rvm-prompt.
authored
22 token=${1:-""}
23 format="${format:-""}${token}"
b86c5ed @wayneeseguin rvm-prompt has been rewritten to be flexible.
authored
24 }
25
ef5c0fa @wayneeseguin Begone relic of the past.
authored
26 rvm_gemset_separator="${rvm_gemset_separator:-"@"}"
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
27 ruby=$(
28 builtin command -v ruby | GREP_OPTIONS="" \grep -v $rvm_path/bin/ruby
29 )
30 if
31 [[ -n "$ruby" && -n "$(echo "$ruby" | awk '/rvm/{print}')" ]]
32 then
b86c5ed @wayneeseguin rvm-prompt has been rewritten to be flexible.
authored
33 unset format
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
34 while
35 [[ $# -gt 0 ]]
36 do
37 token="$1"
38 shift
b86c5ed @wayneeseguin rvm-prompt has been rewritten to be flexible.
authored
39 case "$token" in
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
40 i|interpreter) add "interpreter" ;;
41 v|version) add "version" ;;
42 p|patchlevel) add "patchlevel" ;;
43 r|revision) add "revision" ;;
44 a|architecture) add "architecture" ;;
45 g|gemset) add "gemset" ;;
46 u|unicode) add "unicode" ;;
47 s|system) ;; #skip when in ruby
48 -d|--no-default) no_default=1 ;;
49 *) add_raw_token "$token" ;;
b86c5ed @wayneeseguin rvm-prompt has been rewritten to be flexible.
authored
50 esac
51 done
52
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
53 if
54 [[ -z "${format:-""}" && -z "$no_default" ]]
55 then
56 for default in interpreter version patchlevel gemset
57 do
6976a01 @wayneeseguin Slight refactoring in rvm-prompt.
authored
58 add "$default"
59 done
b86c5ed @wayneeseguin rvm-prompt has been rewritten to be flexible.
authored
60 fi
680aa55 @wayneeseguin s/which/POSIX command -v/g
authored
61 ruby_string=$(dirname "$ruby" | xargs dirname | xargs basename)
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
62 if
63 [[ -n "$no_default" && -n "${format:-""}" ]]
64 then
5e39d62 @wayneeseguin Addressed Yehudas rvm-prompt slowness query.
authored
65 # Do not display anything if no default flag was provided
66 # and we are using the default ruby
67 # Only people who explicitely ask for this will have the
68 # slight performance penalty associated.
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
69 [[ "$(rvm tools identifier)" != "$(rvm alias show default)" ]] || exit 0
cc6832b @sj26 Added no-default option to rvm-prompt
sj26 authored
70 fi
2658885 @wayneeseguin Bugfix: rvm-prompt when jruby is used.
authored
71 strings=(${ruby_string//-/ })
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
72 if
73 (( ${interpreter_flag:-0} )) || [[ -n "$unicode_flag" ]]
74 then
2658885 @wayneeseguin Bugfix: rvm-prompt when jruby is used.
authored
75 interpreter=${strings[0]}
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
76 (( ${interpreter_prefix_flag:-0} )) && interpreter="-${interpreter}"
fc62742 @wayneeseguin Put back rvm-prompt :/
authored
77 fi
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
78 if
79 (( ${version_flag:-0} )) || [[ -n "$unicode_flag" ]]
80 then
2658885 @wayneeseguin Bugfix: rvm-prompt when jruby is used.
authored
81 version=${strings[1]}
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
82 (( ${version_prefix_flag:-0} )) && version="-${version}"
fc62742 @wayneeseguin Put back rvm-prompt :/
authored
83 fi
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
84 if
85 (( ${#strings[@]} > 2 ))
86 then
87 if
88 (( ${patchlevel_flag:-0} ))
89 then
2658885 @wayneeseguin Bugfix: rvm-prompt when jruby is used.
authored
90 patchlevel=${strings[2]}
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
91 (( ${patchlevel_prefix_flag:-0} )) && patchlevel="-${patchlevel}"
2658885 @wayneeseguin Bugfix: rvm-prompt when jruby is used.
authored
92 fi
fc62742 @wayneeseguin Put back rvm-prompt :/
authored
93 fi
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
94 if
95 (( ${architecture_flag:-0} ))
96 then
fc62742 @wayneeseguin Put back rvm-prompt :/
authored
97 architecture="$(echo "$(ruby -v)" | sed 's/^.*\[//' | sed 's/\].*$//')"
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
98 (( ${architecture_prefix_flag:-0} )) && architecture="-${architecture}"
fc62742 @wayneeseguin Put back rvm-prompt :/
authored
99 fi
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
100 if
101 (( ${gemset_flag:-0} ))
102 then
5f8cfc5 @wayneeseguin Removing usages of =~ so as to not be "idiotic", by the power of GreyCat...
authored
103 case "${GEM_HOME:-""}" in
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
104 (*${rvm_gemset_separator:-"@"}*)
51c7e7e @wayneeseguin removed gemset separator from global initialize.
authored
105 gemset="${rvm_gemset_separator:-"@"}${GEM_HOME/*${rvm_gemset_separator:-"@"}/}"
106 ;;
5f8cfc5 @wayneeseguin Removing usages of =~ so as to not be "idiotic", by the power of GreyCat...
authored
107 esac
c337bff @wayneeseguin Added initial unicode concept for rvm-prompt. Thanks burke!
authored
108 fi
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
109 if
110 (( ${unicode_flag:-0} ))
111 then
c337bff @wayneeseguin Added initial unicode concept for rvm-prompt. Thanks burke!
authored
112 case "$interpreter" in
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
113 (jruby) unicode="" ;;
114 (rbx) unicode="" ;;
115 (ree) unicode="" ;;
116 (macruby) unicode="" ;;
117 (maglev) unicode="" ;;
118 (ironruby) unicode="" ;;
119 (system) unicode="" ;;
120 (goruby) unicode="";;
121 (ruby)
5f8cfc5 @wayneeseguin Removing usages of =~ so as to not be "idiotic", by the power of GreyCat...
authored
122 case ${version:-""} in
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
123 (1.8.6) unicode="➇❻" ;;
124 (1.8.7) unicode="➇❼" ;;
125 (1.8*) unicode="" ;;
126 (1.9.1) unicode="➈❶" ;;
127 (1.9.2) unicode="➈❷" ;;
128 (1.9.3) unicode="➈❸" ;;
129 (*) unicode="⦿" ;;
c337bff @wayneeseguin Added initial unicode concept for rvm-prompt. Thanks burke!
authored
130 esac ;;
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
131 (*) unicode="⦿" ;;
707dc21 @wayneeseguin Performance: Use GEM_HOME instead of going through gem in rvm-prompt to ...
authored
132 esac
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
133 if
134 echo "$ruby_string" | GREP_OPTIONS="" \grep '-head' >/dev/null 2>&1
135 then
62d53e7 @elia Update unicode symbols
elia authored
136 unicode="${unicode}"
bb7d6f9 @wayneeseguin Added unicode char for head. Thanks khaase!
authored
137 fi
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
138 (( ${unicode_prefix_flag:-0} )) && unicode="-${unicode}"
2abdd30 @griff Restructured how the - separator gets inserted in rvm-prompt to remove t...
griff authored
139 fi
140 eval "echo \"$format\""
b6d9c89 @wayneeseguin Added 'system' output to rvm-prompt, thanks workmad3.
authored
141 else
3006fce @mpapis formating rvm-prompt, update #1042
mpapis authored
142 while
143 (( $# ))
144 do
145 token="$1"
146 shift
cf3bc57 Require s (system) switch to return "system" when system ruby is in use.
Derek authored
147 case "$token" in
5f8cfc5 @wayneeseguin Removing usages of =~ so as to not be "idiotic", by the power of GreyCat...
authored
148 s|system) echo "system" ;;
cf3bc57 Require s (system) switch to return "system" when system ruby is in use.
Derek authored
149 esac
150 done
a4a87ca @wayneeseguin rvm-prompt works when you copy scripts/rvm-prompt to your path now :)
authored
151 fi
Something went wrong with that request. Please try again.