-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRakefile
114 lines (97 loc) · 3.75 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#require 'pry'
# To sync Xcode settings into working dir:
# rsync -vcr --exclude=IDE* ~/Library/Developer/Xcode/UserData/ .
DIRS = ['CodeSnippets', 'FontAndColorThemes', 'KeyBindings']
FILES_IN_DIRS = []
DEST = File.expand_path('~/Library/Developer/Xcode/UserData')
task :default => ['symlink:all', 'update_prefs']
namespace :symlink do
desc "Symlinks dirs #{DIRS.join(",")} and all files in #{FILES_IN_DIRS.join(",")} into editor preferences folder"
task :all => DIRS + FILES_IN_DIRS
DIRS.each do |dir_to_symlink|
desc "Symlinks #{dir_to_symlink} into #{DEST}"
task dir_to_symlink.to_sym do
safe_symlink2(dir_to_symlink)
end
end
FILES_IN_DIRS.each do |dir_with_files|
desc "Symlinks all files in #{dir_with_files} into #{File.join(DEST, dir_with_files)}"
task dir_with_files.to_sym do
Dir.foreach(File.join(File.expand_path('.'), dir_with_files)) do |file|
next if file == '.' or file == '..'
safe_symlink2(File.join(dir_with_files, file))
end
end
end
end
desc "Updates a handful of internal Xcode preferences so that you don't have to waste time hunting around for them"
task :update_prefs do
puts "Updating Xcode Preferences..."
run('defaults write com.apple.dt.Xcode DVTTextShowLineNumbers -bool true')
run('defaults write com.apple.dt.Xcode IDEEditorCoordinatorTarget_Click FocusedEditor')
run('defaults write com.apple.dt.Xcode DVTTextWrappedLinesIndentWidth -int 2')
run('defaults write com.apple.dt.Xcode IDEKeyBindingCurrentPreferenceSet akitchen.idekeybindings')
run('defaults write com.apple.dt.Xcode IDEBuildingContinueBuildingAfterErrors -bool true')
run('defaults write com.apple.dt.Xcode IDEEditorCoordinatorTarget_DoubleClick SeparateTab')
run('defaults write com.apple.dt.Xcode DVTTextEditorTrimWhitespaceOnlyLines -bool true')
run('defaults write com.apple.dt.Xcode DVTFontAndColorCurrentTheme akitchen.dvtcolortheme')
end
namespace :reset do
desc "Resets dirs #{DIRS.join(",")} and all files in #{FILES_IN_DIRS.join(",")}"
task :all => DIRS + FILES_IN_DIRS
DIRS.each do |dir_to_reset|
desc "Resets symlinked dir #{File.join(DEST, dir_to_reset)}"
task dir_to_reset.to_sym do
reset_from_bak(File.join(DEST, dir_to_reset))
end
end
FILES_IN_DIRS.each do |dir_with_files|
desc "Resets all symlinked files in #{File.join(DEST, dir_with_files)}"
task dir_with_files.to_sym do
Dir.foreach(File.join(File.expand_path('.'), dir_with_files)) do |file|
next if file == '.' or file == '..'
reset_from_bak(File.join(DEST, dir_with_files, file))
end
end
end
end
desc "Symlinks dirs #{DIRS.join(",")} and all files in #{FILES_IN_DIRS.join(",")} into editor preferences folder"
task :symlink_all do
cwd = File.expand_path('.')
DIRS.each do |dir|
safe_symlink(File.join(cwd, dir), File.join(DEST, dir))
end
FILES_IN_DIRS.each do |dir|
Dir.foreach(File.join(cwd, dir)) do |file|
next if file == '.' or file == '..'
safe_symlink(File.join(cwd, dir, file), File.join(DEST, dir, file))
end
end
end
task :reset do
cwd = File.expand_path('.')
DIRS.each do |dir|
reset_from_bak(File.join(DEST, dir))
end
FILES_IN_DIRS.each do |dir|
Dir.foreach(File.join(cwd, dir)) do |file|
next if file == '.' or file == '..'
reset_from_bak(File.join(DEST, dir, file))
end
end
end
def safe_symlink2(file)
safe_symlink(File.join(File.expand_path('.'), file), File.join(DEST, file))
end
def safe_symlink(from, to)
run("rm #{to}") if File.symlink?(to)
run("mv #{to} #{to}.bak") if File.exist?(to)
run("ln -s #{from} #{to}")
end
def reset_from_bak(file)
run("rm #{file} && mv #{file}.bak #{file}") if(File.symlink?(file) && File.exist?("#{file}.bak"))
end
def run(cmd)
puts "Running :#{cmd}\n\n"
`#{cmd}`
end