-
Notifications
You must be signed in to change notification settings - Fork 78
/
Rakefile
60 lines (53 loc) · 1.79 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
# -*- mode: ruby -*-
# vi: set ft=ruby ts=2 sw=2 sts=2 et :
require 'date'
require 'find'
module OS
def OS.win?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def OS.unix?
!OS.win?
end
def OS.linux?
OS.unix? and !OS.mac?
end
end
desc "Installs the Chrome Developer Tools custom theme file"
task :install, :backup do |t, args|
args.with_defaults(:backup => nil)
home_dir = File.expand_path('~')
chrome_dirs = []
if OS.mac?
chrome_dirs.push File.join(home_dir, "Library", "Application Support", "Google", "Chrome")
chrome_dirs.push File.join(home_dir, "Library", "Application Support", "Google", "Chrome Canary")
elsif OS.win?
chrome_dirs.push File.join(home_dir, "AppData", "Local", "Google", "Chrome", "User Data")
chrome_dirs.push File.join(home_dir, "AppData", "Local", "Google", "Chrome SxS", "User Data")
else
puts "Unsuported OS..."
end
chrome_dirs.each { |chrome_dir|
if File.exist?(chrome_dir)
Dir.glob(File.join(chrome_dir, "*", "")).each { |profile_dir|
profile_name = File.basename(profile_dir)
if profile_name =~ /(Default|Profile [0-9]+)/
css_new = File.join(File.dirname(__FILE__), "Custom.css")
css_old = File.join(profile_dir, "User StyleSheets", "Custom.css")
if args[:backup] and File.exist?(css_old)
time_now = Time.now.strftime('%Y%m%d-%H%M%S')
css_backup = File.join(profile_dir, "User StyleSheets", "Custom.css.#{time_now}")
puts "Creating backup: #{css_backup}"
FileUtils.cp css_old, css_backup
end
puts "Copying: #{css_new} -> #{css_old}"
FileUtils.cp css_new, css_old
end
}
end
}
end
task :default => [:install]