forked from romanblanco/dotfiles
/
install.rb
57 lines (50 loc) · 1021 Bytes
/
install.rb
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
def main
dotfiles.each { |file| try_linking(file) }
end
def dotfiles
[
"rgignore",
"bash_profile",
"bashrc",
"config/nvim/init.vim",
"gitconfig",
"gitignore",
"gitmessage",
"i3/config",
"i3/status",
"irbrc",
"pryrc",
"ssh/config",
"tmux.conf",
"Xresources",
]
end
def try_linking(file)
if File.exist?(target(file))
puts "skipping #{ target(file) }: #{ skip_reason(target(file)) }"
elsif File.symlink?(target(file))
puts "rewriting #{ target(file) }"
File.delete(target(file))
File.symlink(source(file), target(file))
else
puts "linking #{ target(file) }"
File.symlink(source(file), target(file))
end
end
def source(file)
File.expand_path("~/etc/#{ file }")
end
def target(file)
File.expand_path("~/.#{ file }")
end
def skip_reason(file)
if File.symlink?(file)
"already linked"
else
"file already exists. delete or move before reinstalling."
end
end
def path_for(file)
File.expand_path(file)
end
main