-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRakefile
More file actions
197 lines (184 loc) · 4.87 KB
/
Rakefile
File metadata and controls
197 lines (184 loc) · 4.87 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
require 'rake'
require 'erb'
desc "install the dot files into user's home directory"
task :install do
install_zgen
switch_to_zsh
#install_oh_my_fish
#switch_to_fish
install_fzf
replace_all = false
files = Dir['*'] - %w[Rakefile README.md config settings]
files.each do |file|
system %Q{mkdir -p "$HOME/.#{File.dirname(file)}"} if file =~ /\//
if File.exist?(File.join(ENV['HOME'], ".#{file.sub(/\.erb$/, '')}"))
if File.identical? file, File.join(ENV['HOME'], ".#{file.sub(/\.erb$/, '')}")
puts "identical ~/.#{file.sub(/\.erb$/, '')}"
elsif replace_all
replace_file(file)
else
print "overwrite ~/.#{file.sub(/\.erb$/, '')}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
replace_file(file)
when 'y'
replace_file(file)
when 'q'
exit
else
puts "skipping ~/.#{file.sub(/\.erb$/, '')}"
end
end
else
link_file(file)
end
end
install_config
make_vim_tmp_dir
end
def replace_file(file)
system %Q{rm -rf "$HOME/.#{file.sub(/\.erb$/, '')}"}
link_file(file)
end
def link_file(file)
if file =~ /.erb$/
puts "generating ~/.#{file.sub(/\.erb$/, '')}"
File.open(File.join(ENV['HOME'], ".#{file.sub(/\.erb$/, '')}"), 'w') do |new_file|
new_file.write ERB.new(File.read(file)).result(binding)
end
else
puts "linking ~/.#{file}"
system %Q{ln -s "$PWD/#{file}" "$HOME/.#{file}"}
end
end
def link_file_to_root(file)
#ignore .erb files as root
unless file =~ /.erb$/
puts "linking /root/.#{file}"
system %Q{[ -f /root/.zgen ] && ( sudo ln -s "$PWD/#{file}" "/root/.#{file}")}
end
end
def switch_to_zsh
if ENV["SHELL"] =~ /zsh/
puts "using zsh"
else
print "switch to zsh? (recommended) [ynq] "
case $stdin.gets.chomp
when 'y'
puts "switching to zsh"
system %Q{chsh -s `which zsh`}
when 'q'
exit
else
puts "skipping zsh"
end
end
end
def switch_to_fish
if ENV["SHELL"] =~ /fish/
puts "using fish"
else
print "switch to fish? (recommended) [ynq] "
case $stdin.gets.chomp
when 'y'
puts "switching to fish"
system %Q{chsh -s `which fish`}
when 'q'
exit
else
puts "skipping fish"
end
end
end
def install_zgen
if File.exist?(File.join(ENV['HOME'], ".zgen"))
puts "found ~/.zgen"
else
print "install zgen? ynq] "
case $stdin.gets.chomp
when 'y'
puts "installing zgen"
system %Q{git clone https://github.com/tarjoilija/zgen.git $HOME/.zgen}
when 'q'
exit
else
puts "skipping zgen, you will need to change ~/.zshrc"
end
end
end
def install_oh_my_fish
if File.exist?(File.join(ENV['HOME'], ".oh-my-fish"))
puts "found ~/.oh-my-fish"
else
print "install oh-my-fish? ynq] "
case $stdin.gets.chomp
when 'y'
puts "installing oh-my-fish"
system %Q{git clone git://github.com/bpinto/oh-my-fish.git $HOME/.oh-my-fish}
when 'q'
exit
else
puts "skipping oh-my-fish"
end
end
end
def make_vim_tmp_dir
if !File.exists?(File.join(ENV['HOME'],".vim/tmp"))
system %Q{mkdir -p "$HOME/.vim/tmp"}
puts "created dir ~/.vim/tmp for vim swap files"
else
puts "found dir ~/.vim/tmp for vim swap files"
end
end
def install_config
replace_all = false
configfiles = Dir['config/*']
if !File.exists?(File.join(ENV['HOME'],".config"))
system %Q{mkdir -p "$HOME/.config/."}
end
configfiles.each do |file|
system %Q{mkdir -p "$HOME/.config/#{File.dirname(file)}"} if file =~ /\//
if File.exist?(File.join(ENV['HOME'], ".#{file.sub(/\.erb$/, '')}"))
if File.identical? file, File.join(ENV['HOME'], ".#{file.sub(/\.erb$/, '')}")
puts "identical ~/.#{file.sub(/\.erb$/, '')}"
elsif replace_all
replace_file(file)
else
print "overwrite ~/.#{file.sub(/\.erb$/, '')}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
replace_file(file)
when 'y'
replace_file(file)
when 'q'
exit
else
puts "skipping ~/.#{file.sub(/\.erb$/, '')}"
end
end
else
link_file(file)
end
end
end
def install_fzf
if !File.exists?(File.join(ENV['HOME'],".fzf"))
puts "Installing fzf..."
system %Q{git clone https://github.com/junegunn/fzf.git ~/.fzf}
system %Q{~/.fzf/install}
end
end
desc "link the dot files into root home directory"
task :linkroot do
puts "linking dotfiles to /root/dotfiles"
system %Q{sudo [ ! -e /root/dotfiles ] && ( sudo ln -s "$HOME/dotfiles" "/root/dotfiles")}
puts "linking zgen to /root/.zgen"
system %Q{sudo [ ! -e /root/.zgen ] && ( sudo ln -s "$HOME/.zgen" "/root/.zgen")}
replace_all = false
files = Dir['*'] - %w[Rakefile README.md config settings]
files.each do |file|
link_file_to_root(file)
end
end