|
1 #!/usr/bin/env ruby |
|
2 # vim: et sts=2 sw=2 fdm=marker |
|
3 # encoding: UTF-8 |
|
4 |
|
5 # we don't yet have rbenv so keep safe for ruby 1.8 |
|
6 |
|
7 if `which git` == '' |
|
8 puts "please install git" |
|
9 exit 1 |
|
10 end |
|
11 |
|
12 |
|
13 # util {{{ |
|
14 # just checks and bails after each call |
|
15 def do_cmds (*cmds) |
|
16 cmds.each do |cmd| |
|
17 puts "$ #{cmd}" |
|
18 system( cmd ) or exit $? |
|
19 end |
|
20 end |
|
21 |
|
22 #checks for the first line and if it's not there, appends the whole set |
|
23 def add_if_missing (fn, lines) |
|
24 match = lines.lines.first.chomp |
|
25 add = false |
|
26 |
|
27 if File.exists?(fn) |
|
28 File.open(fn) do |file| |
|
29 if file.each_line.none? { |line| line.chomp == match } |
|
30 add = true |
|
31 end |
|
32 end |
|
33 else |
|
34 add = true |
|
35 end |
|
36 |
|
37 if add == true |
|
38 File.open(fn, 'a') do |append| |
|
39 append << lines |
|
40 append << $/ |
|
41 end |
|
42 |
|
43 puts "Added to #{fn}:" |
|
44 puts lines + $/ |
|
45 end |
|
46 |
|
47 end |
|
48 |
|
49 def replace_line (fn, match, replace) |
|
50 buf = [] |
|
51 changed = false |
|
52 |
|
53 File.open(fn) do |file| |
|
54 file.each_line do |line| |
|
55 buf << if line.match(match) |
|
56 changed = true |
|
57 replace |
|
58 else |
|
59 line |
|
60 end |
|
61 end |
|
62 end |
|
63 |
|
64 if changed |
|
65 File.open( fn + ".tmp~", 'w' ) do |file| |
|
66 buf.each do |line| |
|
67 file.puts line |
|
68 end |
|
69 end |
|
70 puts 'changes in #{fn}.tmp~' |
|
71 else |
|
72 puts 'no change' |
|
73 end |
|
74 end |
|
75 # }}} |
|
76 |
|
77 |
|
78 # oh-my-zsh {{{ |
|
79 # i have a custom theme and the omz install complains about already |
|
80 # having a directory there. remove, install, then revert my stuff |
|
81 # out of hg |
|
82 |
|
83 if Dir.exists?('.oh-my-zsh/.git') |
|
84 puts "oh-my-zsh already installed" |
|
85 else |
|
86 puts "Installing oh-my-zsh..." |
|
87 |
|
88 do_cmds \ |
|
89 'rm -r .oh-my-zsh', |
|
90 'git clone git://github.com/robbyrussell/oh-my-zsh.git .oh-my-zsh', |
|
91 'hg stat -dn0 -I .oh-my-zsh/ | xargs -0 hg revert' |
|
92 |
|
93 end |
|
94 |
|
95 # }}} |
|
96 |
|
97 |
|
98 add_if_missing '.bash_profile', 'export PATH=~/bin:$PATH' |
|
99 |
|
100 add_if_missing '.zshrc', <<END |
|
101 typeset -U path |
|
102 path=(~/bin "$path[@]") |
|
103 END |
|
104 |
|
105 |
|
106 # plenv {{{ |
|
107 |
|
108 if Dir.exists?('.plenv') |
|
109 puts "plenv already installed" |
|
110 else |
|
111 puts "Installing plenv..." |
|
112 |
|
113 do_cmds \ |
|
114 'git clone git://github.com/tokuhirom/plenv.git .plenv', |
|
115 'git clone git://github.com/tokuhirom/Perl-Build.git .plenv/plugins/perl-build/' |
|
116 |
|
117 |
|
118 add_if_missing '.bash_profile', <<END |
|
119 export PATH="$HOME/.plenv/bin:$PATH" |
|
120 eval "$(plenv init -)" |
|
121 END |
|
122 |
|
123 add_if_missing '.zshrc', <<END |
|
124 path=(~/.plenv "$path[@]") |
|
125 eval "$(plenv init - zsh)" |
|
126 END |
|
127 |
|
128 end |
|
129 |
|
130 # }}} |
|
131 |
|
132 |
|
133 # rbenv {{{ |
|
134 |
|
135 # git clone https://github.com/sstephenson/rbenv.git ~/.rbenv |
|
136 # git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build |
|
137 # echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile |
|
138 # echo 'eval "$(rbenv init -)"' >> ~/.bash_profile |
|
139 if Dir.exists?('.rbenv') |
|
140 puts "rbenv already installed" |
|
141 else |
|
142 puts "Installing rbenv..." |
|
143 |
|
144 do_cmds \ |
|
145 'git clone https://github.com/sstephenson/rbenv.git .rbenv', |
|
146 'git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build/' |
|
147 |
|
148 |
|
149 add_if_missing '.bash_profile', <<END |
|
150 export PATH="$HOME/.rbenv/bin:$PATH" |
|
151 eval "$(rbenv init -)" |
|
152 END |
|
153 |
|
154 add_if_missing '.zshrc', <<END |
|
155 path=(~/.rbenv "$path[@]") |
|
156 eval "$(rbenv init - zsh)" |
|
157 END |
|
158 |
|
159 end |
|
160 |
|
161 # }}} |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 # vundle {{{ |
|
167 |
|
168 # }}} |
|
169 |
|
170 |
|
171 |