1 #!/usr/bin/env ruby |
1 #!/usr/bin/env ruby |
2 # vim: et sts=2 sw=2 fdm=marker |
2 # vim: et sts=2 sw=2 fdm=marker |
3 # encoding: UTF-8 |
|
4 |
3 |
5 # we don't yet have rbenv so keep safe for ruby 1.8 |
4 # we don't yet have rbenv so keep safe for ruby 1.8 |
6 |
5 |
7 if `which git` == '' |
6 if `which git` == '' |
8 puts "please install git" |
7 puts "please install git" |
9 exit 1 |
8 exit 1 |
10 end |
9 end |
11 |
10 |
12 |
11 |
13 # util {{{ |
12 # just checks and bails after each call |
14 # just checks and bails after each call |
13 def do_cmds (*cmds) |
15 def do_cmds (*cmds) |
14 cmds.each do |cmd| |
16 cmds.each do |cmd| |
15 puts "$ #{cmd}" |
17 puts "$ #{cmd}" |
16 system( cmd ) or exit $? |
18 system( cmd ) or exit $? |
|
19 end |
|
20 end |
17 end |
|
18 end |
21 |
19 |
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 |
20 |
77 |
21 |
78 # oh-my-zsh {{{ |
22 # oh-my-zsh {{{ |
79 # i have a custom theme and the omz install complains about already |
23 # i have a custom theme and the omz install complains about already |
80 # having a directory there. remove, install, then revert my stuff |
24 # having a directory there. remove, install, then revert my stuff |
84 puts "oh-my-zsh already installed" |
28 puts "oh-my-zsh already installed" |
85 else |
29 else |
86 puts "Installing oh-my-zsh..." |
30 puts "Installing oh-my-zsh..." |
87 |
31 |
88 do_cmds \ |
32 do_cmds \ |
89 'rm -r .oh-my-zsh', |
|
90 'git clone git://github.com/robbyrussell/oh-my-zsh.git .oh-my-zsh', |
33 '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' |
34 'hg stat -dn0 -I .oh-my-zsh/ | xargs -0 hg revert' |
92 |
35 |
93 end |
36 end |
94 |
37 |
95 # }}} |
38 # }}} |
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 |
39 |
105 |
40 |
106 # plenv {{{ |
41 # plenv {{{ |
107 |
42 |
108 if Dir.exists?('.plenv') |
43 if Dir.exists?('.plenv') |
111 puts "Installing plenv..." |
46 puts "Installing plenv..." |
112 |
47 |
113 do_cmds \ |
48 do_cmds \ |
114 'git clone git://github.com/tokuhirom/plenv.git .plenv', |
49 'git clone git://github.com/tokuhirom/plenv.git .plenv', |
115 'git clone git://github.com/tokuhirom/Perl-Build.git .plenv/plugins/perl-build/' |
50 '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 |
51 |
128 end |
52 end |
129 |
53 |
130 # }}} |
54 # }}} |
131 |
55 |
132 |
56 |
133 # rbenv {{{ |
57 # 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') |
58 if Dir.exists?('.rbenv') |
140 puts "rbenv already installed" |
59 puts "rbenv already installed" |
141 else |
60 else |
142 puts "Installing rbenv..." |
61 puts "Installing rbenv..." |
143 |
62 |
144 do_cmds \ |
63 do_cmds \ |
145 'git clone https://github.com/sstephenson/rbenv.git .rbenv', |
64 'git clone https://github.com/sstephenson/rbenv.git .rbenv', |
146 'git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build/' |
65 'git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build/' |
147 |
66 |
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 |
67 end |
160 |
|
161 # }}} |
68 # }}} |
162 |
69 |
163 |
70 |
164 |
71 |
165 |
|
166 # vundle {{{ |
|
167 |
|
168 # }}} |
|
169 |
|
170 |
|
171 |
|