forked from holman/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
68 lines (58 loc) · 1.89 KB
/
Rakefile
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
require 'fileutils'
desc "Install everything into the system"
task :default => [:symlinks, :os_dependent]
desc "Only symlink files"
task :symlinks do
linkables = Dir.glob('*/**{.symlink}')
skip_all = false
overwrite_all = false
backup_all = false
linkables.each do |linkable|
overwrite = false
backup = false
file = linkable.split('/').last.gsub(/\.symlink$/, "")
target = "#{ENV["HOME"]}/.#{file}"
if File.exists?(target) || File.symlink?(target)
unless skip_all || overwrite_all || backup_all
puts "File already exists: #{target}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all"
case STDIN.gets.chomp
when 'o' then overwrite = true
when 'b' then backup = true
when 'O' then overwrite_all = true
when 'B' then backup_all = true
when 'S' then skip_all = true
end
end
if overwrite || overwrite_all
FileUtils.rm_rf(target)
`ln -s "$PWD/#{linkable}" "#{target}"`
elsif backup || backup_all
`mv "$HOME/.#{file}" "$HOME/.#{file}.backup"` if
`ln -s "$PWD/#{linkable}" "#{target}"`
elsif skip_all
# do nothing
end
else
`ln -s "$PWD/#{linkable}" "#{target}"`
end
end
end
OS_DEPENDENT_FILES = {
"vscode/settings.json" => {
"Darwin" => "~/Library/Application Support/Code/User/settings.json",
"Linux" => "~/.config/Code/User/settings.json"
},
"linux/terimnator-config" => {
"Linux" => "~/.config/terminator/config"
}
}
desc "Symlink some files to specific places depending on the OS"
task :os_dependent do
os = `uname`.chomp
OS_DEPENDENT_FILES.each do |linkable, targets|
if targets[os] && target = File.expand_path(targets[os])
`mkdir -p #{File.dirname(target)}`
`ln -s "#{File.expand_path(linkable)}" "#{target}"`
end
end
end