forked from edgecase/pairing-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
93 lines (75 loc) · 2.11 KB
/
Copy pathRakefile
File metadata and controls
93 lines (75 loc) · 2.11 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
require 'rubygems'
require 'rake'
desc "symlink all dot files and bin directory"
task :default do
files = Dir.glob('.*') - ['.git', '.gitmodules', '.', '..']
files << 'bin'
symlink files
# non-pairing machines should not symlink the .gitconfig
print "are you on an EdgeCase pairing machine? [yn] "
if gets.chomp.downcase == 'n' && file_identical?('.gitconfig')
directory = File.dirname(__FILE__)
sh "rm #{ENV['HOME']}/.gitconfig"
sh "cp #{File.join(directory, '.gitconfig')} #{File.join(ENV['HOME'], '.gitconfig')}"
%w[ name email ].each do |param|
current = `git config --global user.#{param}`
print "enter your #{param} (leave blank to keep #{current.chomp}): "
replacement = gets.chomp
unless replacement.empty?
sh "git config --global --replace-all user.#{param} '#{replacement}'"
end
end
end
end
def symlink(files)
files.each do |file|
case
when file_identical?(file) then skip_identical_file(file)
when replace_all_files? then link_file(file)
when file_missing?(file) then link_file(file)
else prompt_to_link_file(file)
end
end
end
# FILE CHECKS
def file_exists?(file)
File.exists?("#{ENV['HOME']}/#{file}")
end
def file_missing?(file)
!file_exists?(file)
end
def file_identical?(file)
File.identical? file, File.join(ENV['HOME'], "#{file}")
end
def replace_all_files?
@replace_all == true
end
# FILE ACTIONS
def prompt_to_link_file(file)
print "overwrite? ~/#{file} [ynaq] "
case $stdin.gets.chomp
when 'y' then replace_file(file)
when 'a' then replace_all(file)
when 'q' then exit
else skip_file(file)
end
end
def link_file(file)
puts " => symlinking #{file}"
directory = File.dirname(__FILE__)
sh("ln -s #{File.join(directory, file)} #{ENV['HOME']}/#{file}")
end
def replace_file(file)
sh "rm -rf #{ENV['HOME']}/#{file}"
link_file(file)
end
def replace_all(file)
@replace_all = true
replace_file(file)
end
def skip_file(file)
puts " => skipping ~/#{file}"
end
def skip_identical_file(file)
puts " => skipping identical ~/#{file}"
end