-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path40-ruby.sh
More file actions
89 lines (71 loc) · 2.69 KB
/
40-ruby.sh
File metadata and controls
89 lines (71 loc) · 2.69 KB
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
# ruby helpers
ruby-env-help(){
cat <<EOF
Two ENV variables control the 'gem' command:
GEM_HOME: the single path to a gem dir where gems are installed
GEM_PATH: a standard PATH to gem dirs where gems are found
A gem directory is a directory that holds gems. The 'gem' command will lay
out and utilize the following structure:
bin # installed bin scripts
cache # .gem files ex: cache/gem_name.gem
doc # rdoc/ri ex: doc/gem_name/rdoc
gems # gem file ex: gems/gem_name/lib/gem_name.rb
specifications # gemspecs ex: specifications/gem_name.gemspec
As an example of usage:
EOF
cat | pygmentize -l ruby <<EOF
export GEM_HOME=a
export GEM_PATH=a
gem install rack
gem list # shows rack
export GEM_HOME=b
export GEM_PATH=b
gem install rake
gem list # shows rake (not rack)
export GEM_PATH=a:b
gem list # shows rake and rack
And if you set GEM_HOME=a:b, you will install into the 'a:b' directory :)
EOF
}
export RUBY_VERSION="$(ruby -v | cut -f1 -dp | awk '{print $2}')"
export GEM_HOME="$(ruby -e 'print "#{Gem.user_dir}"')"
if [[ ! ${GEM_PATH} =~ ${GEM_HOME} ]]; then
export GEM_PATH="${HOME}/.gem/ruby/${RUBY_VERSION}"
fi
if [[ $RUBY_VERSION =~ "1.9" ]]; then
export GEM_PATH="/opt/ruby1.9/lib/ruby/gems/1.9.1:${GEM_PATH}"
fi
if [[ ! $PATH =~ $GEM_HOME ]]; then
export PATH="${GEM_HOME}/bin:${PATH}"
fi
[[ -f ~/.gemrc ]] || {
cat > ~/.gemrc <<EOF
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
EOF
}
ruby-toggle(){
if [[ "${RUBY_VERSION}" =~ "1.9" ]]; then
echo -e ">> Enabling ruby ${YELLOW}2${RESET}\007"
# set ruby 2.2 by deleting ~/.local/bin links
for x in {ruby,bundle,rake}; do
rm ~/.local/bin/${x} 2>/dev/null
done
PATH=${PATH/"${GEM_HOME}/bin:"/}
export RUBY_VERSION="$(/sbin/ruby -v | cut -f1 -dp | awk '{print $2}')"
export GEM_HOME="$(/sbin/ruby -e 'print "#{Gem.user_dir}"')"
export PATH="${GEM_HOME}/bin:${PATH}"
else
echo -e ">> Enabling ruby ${YELLOW}1.9${RESET}\007"
# set ruby 1.9 by creating links in ~/.local/bin
for x in {ruby,bundle,rake}; do
rm ~/.local/bin/${x} 2>/dev/null
ln -s /opt/ruby1.9/bin/${x} ~/.local/bin/${x}
done
PATH=${PATH/"${GEM_HOME}/bin:"/}
export RUBY_VERSION="$(/sbin/ruby-1.9 -v | cut -f1 -dp | awk '{print $2}')"
export GEM_HOME="$(/sbin/ruby-1.9 -e 'print "#{Gem.user_dir}"')"
export PATH="${GEM_HOME}/bin:${PATH}"
fi
}
archlinux-ruby(){ ruby-toggle; }