-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
rvm-prompt
executable file
·96 lines (84 loc) · 2.54 KB
/
rvm-prompt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
add(){
token="$1"
eval "${token}_flag=1" ; shift
if [[ ! -z "$format" ]] ; then
format="${format}-\$${token}"
else
format="\$${token}"
fi
}
rvm_gemset_separator=${rvm_gemset_separator:-"+"}
if [[ ! -z "$(which ruby 2>/dev/null | awk '/rvm/{print}')" ]] ; then
unset format
while [[ $# -gt 0 ]] ; do
token="$1" ; shift
case "$token" 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) unicode_flag=1 ;;
*) echo "Unrecognized command line option '$token' for $0" ; exit 1 ;;
esac
done
if [[ -z "$format" ]] ; then
add "interpreter"
add "version"
add "patchlevel"
add "gemset"
fi
ruby_string=$(dirname "$(which ruby 2>/dev/null)" | xargs dirname | xargs basename)
if [[ ! -z "$interpreter_flag" ]] ; then
interpreter="$(echo $ruby_string | awk -F'-' '{print $1}')"
fi
if [[ ! -z "$version_flag" ]] ; then
version="$(echo $ruby_string | awk -F'-' '{print $2}')"
fi
if [[ ! -z "$patchlevel_flag" ]] ; then
patchlevel=$(echo $ruby_string | awk -F'-' '{print $3}')
fi
if [[ ! -z "$architecture_flag" ]] ; then
architecture="$(echo "$(ruby -v)" | sed 's/^.*\[//' | sed 's/\].*$//')"
fi
if [[ ! -z "$gemset_flag" ]] ; then
gemset="$(echo $GEM_HOME | awk -F${rvm_gemset_separator} '{print $2}')"
if [[ ! -z "$gemset" ]] ; then gemset="${rvm_gemset_separator}$gemset" ; fi
fi
if [[ ! -z "$unicode_flag" ]] ; then
case "$interpreter" in
jruby) unicode="☯" ;;
rbx) unicode="☃" ;;
ree) unicode="✈" ;;
macruby) unicode="⌘" ;;
maglev) unicode="㎖" ;;
ironruby) unicode="♭" ;;
mput) unicode="⎈" ;;
system) unicode="➆" ;;
ruby)
case "$version" in
1.8.6) unicode="❻" ;;
1.8.7) unicode="❼" ;;
1.9.1) unicode="❶" ;;
1.9.2) unicode="❷" ;;
*) unicode="♢" ;;
esac ;;
*) unicode="♢" ;;
esac
if [[ ! -z "$(echo $ruby_string | awk '/-head/')" ]] ; then
unicode="${unicode}〠"
fi
# TODO: Architecture
# TODO: gemset
echo $unicode
else
command="prompt=\"$format\""
eval "$command"
echo "$prompt" | sed 's#-\s*$##' | sed 's#-'${rvm_gemset_separator}'#'${rvm_gemset_separator}'#'
fi
else
echo "system"
fi
exit 0