forked from ascarter/BBEdit-ApplicationSupport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
76 lines (67 loc) · 2.05 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
69
70
71
72
73
74
75
76
require 'rake'
require 'erb'
require 'fileutils'
task :default => [ :install ]
desc "Install BBEdit support files to Application Support/BBEdit"
task :install do
replace_all = false
source_root = File.expand_path(File.join(__FILE__, '..'))
source_dirs = [
'Clippings', 'Color Schemes', 'Language Modules', 'Preview CSS',
'Scripts', 'Text Filters'
]
home_dir = File.expand_path(ENV['HOME'])
# Find application support directory
appsupport_root = File.join(home_dir, 'Dropbox', 'Application Support', 'BBEdit')
if not File.exist?(appsupport_root)
appsupport_root = File.join(home_dir, 'Library', 'Application Support', 'BBEdit')
if not File.exist?(appsupport_root)
raise IOError.new('No BBEdit directory found in ~/Dropbox/Application Support or ~/Library/Application Support')
end
end
puts "Installing to #{appsupport_root}"
# Install files
source_dirs.each do |d|
source_dir = File.join(source_root, d)
target_dir = File.join(appsupport_root, d)
# Create the target dir if it doesn't exist
Dir.mkdir(target_dir) unless File.directory?(target_dir)
# Get entry in source
Dir.glob(File.join(source_dir, '*')).each do |f|
filename = File.basename(f)
target = File.join(target_dir, filename)
if File.exist?(target)
if File.identical?(f, target)
puts "Identical #{d}/#{filename}"
else
if replace_all
copy(f, target)
else
print "Replace existing file #{d}/#{filename}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
copy(f, target)
when 'y'
copy(f, target)
when 'q'
puts "Abort"
exit
else
puts "Skipping #{d}/#{filename}"
end
end
end
else
copy(f, target)
end
end
end
puts "Done."
end
def copy(source, target)
dirname = File.dirname(source).split('/').last
filename = File.basename(source)
puts "Copy #{dirname}/#{filename}"
FileUtils.cp_r(source, target)
end