-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·58 lines (50 loc) · 1.23 KB
/
run
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
#!/usr/bin/env ruby -r rubygems -r thor
class Dotfiles < Thor
desc "install", "install the dotfiles in your home"
def install
invoke :bootstrap
Dir.glob(sources) do |file|
target = expanded_target(file)
if create_or_overwrite?(target)
File.symlink(file, target)
end
end
end
desc "bootstrap", "make sure you have some cool gems"
def bootstrap
# This should check for our dependencies. Nothing to do for now.
end
private
def create_or_overwrite?(file)
if File.exists?(file)
overwrite?(file)
else
true
end
end
def overwrite?(file)
return false if our_symlink?(file)
puts "#{File.basename(file)} already exists, what do you want to do? [s]kip, [o]verwrite, [k]eep both."
case $stdin.getc
when "s" then false
when "k"
File.rename(file, file + ".old")
true
when "o"
File.delete(file)
true
else false
end
end
def our_symlink?(file)
# TODO: check that it is pointing to us
File.symlink?(file)
end
def sources
File.join(File.expand_path(File.dirname(__FILE__)), "source", "*")
end
def expanded_target(file)
File.expand_path("~/.#{File.basename(file)}")
end
end
Dotfiles.start