-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappa_workstation.rb
95 lines (82 loc) · 2.3 KB
/
appa_workstation.rb
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
require 'find'
def path_to_workstation_file(filename)
File.join(File.dirname(__FILE__), "workstation/#{filename}")
end
def system_or_exit(command)
puts "Executing #{command}"
system(command) or raise ">>>>>>> Command failed"
end
def workstation(action)
action = 'status' unless action
operations = []
unless File.file?(File.expand_path('~/.gitignore_global'))
if action == 'install'
operations << lambda {
puts 'Installing ~/.gitignore_global'
system_or_exit "cp #{path_to_workstation_file('gitignore_global')} ~/.gitignore_global"
}
else
operations << lambda {
puts 'Global gitignore not found.'
}
end
end
with_application 'Divvy', operations
unless File.file?(File.expand_path('~/Library/Preferences/com.mizage.divvy.plist'))
if action == 'install'
operations << lambda {
puts 'Installing Divvy preferences'
}
else
operations << lambda {
puts 'Divvy preferences not found.'
}
end
end
with_application 'Dropbox', operations
with_application 'Flux', operations
unless File.exists? '/Applications/Screen Sharing.app'
if action == 'install'
operations << lambda {
puts 'Installing Screen Sharing application.'
system_or_exit "ln -s '/System/Library/CoreServices/Screen Sharing.app' /Applications/"
}
else
operations << lambda {
puts 'Screen Sharing application not found.'
}
end
end
with_application 'Numbers', operations
unless `git config core.editor`.start_with? 'emacs'
if action == 'install'
operations << lambda {
puts 'Setting git editor'
system_or_exit 'git config --global core.editor "emacs"'
}
else
operations << lambda {
puts 'git editor not set to emacs'
}
end
end
if operations.count > 0
operations.each do |operation|
operation.call
end
else
puts 'Your setup is up to date.'
end
end
def with_application(application_name, operations)
application_found = false
Find.find '/Applications/' do |path|
application_found = true if path =~ /#{application_name}\.app$/
Find.prune if path =~ /\.app$/
end
if !application_found
operations << lambda {
puts "#{application_name} application not found."
}
end
end