prefnerd 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pn +51 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecd39d3f68a1baa503eba80c41c8ccd5fcd1fdc0
|
4
|
+
data.tar.gz: 7ddd0d8d0bd0eb277db33de325beb93fe2c044d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41f92bdc0ace02ebe0bfe5638fff75e25a751826cf3eee80120cd048e3dc7aa6cabac3c545d4b779596c18b8910cca895a2cb648cf1e94efc42de7f58ad98269
|
7
|
+
data.tar.gz: b946d8bb0e446d33963f7cf917acc919198d8ea1fa5f3851d9fc477e235876456926d6f72508345d9330f5130d54d9fc2918b82f0008f9fea47efc249a343667
|
data/bin/pn
CHANGED
@@ -6,26 +6,69 @@ require 'tempfile'
|
|
6
6
|
PREFERENCES = File.join(ENV['HOME'], 'Library', 'Preferences')
|
7
7
|
PLISTS = File.join(PREFERENCES, '**', '*.plist')
|
8
8
|
|
9
|
-
|
9
|
+
DOMAINS = Hash.new do |_, key|
|
10
|
+
key == '.GlobalPreferences' ? 'NSGlobalDomain' : key
|
11
|
+
end
|
12
|
+
|
13
|
+
%w[defaults diff fswatch system_profiler].each do |dependency|
|
10
14
|
if `which #{dependency}`.length.zero?
|
11
15
|
puts "Missing dependency: #{dependency}"
|
12
16
|
exit 1
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
20
|
+
# Try to get current host UUID.
|
21
|
+
match = File.
|
22
|
+
popen(%w[system_profiler SPHardwareDataType]).
|
23
|
+
read.
|
24
|
+
match(/^\s*Hardware UUID:\s*(.+)$/)
|
25
|
+
CURRENT_HOST_SUFFIX = '.' + (match && match[1]).to_s + '.plist'
|
26
|
+
CURRENT_HOST_PREFIX = '-currentHost '
|
27
|
+
|
16
28
|
def read(plist)
|
17
29
|
# Swallow stderr; it's usually harmless.
|
18
|
-
|
30
|
+
if plist.start_with?(CURRENT_HOST_PREFIX)
|
31
|
+
stdout, stderr, status = Open3.capture3(
|
32
|
+
'defaults', '-currentHost', 'read', plist[CURRENT_HOST_PREFIX.length..-1]
|
33
|
+
)
|
34
|
+
else
|
35
|
+
stdout, stderr, status = Open3.capture3('defaults', 'read', plist)
|
36
|
+
end
|
19
37
|
stdout
|
20
38
|
end
|
21
39
|
|
40
|
+
def debug(string)
|
41
|
+
if ENV['DEBUG']
|
42
|
+
puts "DEBUG: #{string}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def normalize(plist)
|
47
|
+
plist = plist.chomp
|
48
|
+
if plist !~ /\.plist\z/
|
49
|
+
nil
|
50
|
+
elsif plist == File.join(PREFERENCES, File.basename(plist))
|
51
|
+
# File is an immediate child of ~/Library/Preferences; return it sans the
|
52
|
+
# ".plist" extension.
|
53
|
+
DOMAINS[File.basename(plist, '.plist')]
|
54
|
+
elsif plist == File.join(PREFERENCES, 'ByHost', File.basename(plist)) &&
|
55
|
+
plist.end_with?(CURRENT_HOST_SUFFIX)
|
56
|
+
# File is in ~/Library/Preferences/ByHost and matches the UUID of the
|
57
|
+
# current host.
|
58
|
+
CURRENT_HOST_PREFIX + DOMAINS[File.basename(plist).chomp(CURRENT_HOST_SUFFIX)]
|
59
|
+
else
|
60
|
+
plist
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
22
64
|
begin
|
23
65
|
# Build up map of known defaults
|
24
66
|
print 'Reading defaults: '
|
25
67
|
DEFAULTS = {}
|
26
68
|
Dir.glob(PLISTS, File::FNM_DOTMATCH).each do |plist|
|
69
|
+
plist = normalize(plist)
|
27
70
|
print '.'
|
28
|
-
DEFAULTS[plist] = read(plist)
|
71
|
+
DEFAULTS[plist] = read(plist) if plist
|
29
72
|
end
|
30
73
|
puts
|
31
74
|
|
@@ -36,11 +79,13 @@ begin
|
|
36
79
|
'-m',
|
37
80
|
'fsevents_monitor',
|
38
81
|
'-r',
|
39
|
-
|
82
|
+
PREFERENCES,
|
40
83
|
])
|
41
84
|
while line = lines.readline
|
42
|
-
|
43
|
-
|
85
|
+
debug("fswatch -> #{line.inspect}")
|
86
|
+
plist = normalize(line)
|
87
|
+
debug("normalized -> #{plist.inspect}")
|
88
|
+
if plist
|
44
89
|
new_contents = read(plist)
|
45
90
|
new_file = Tempfile.new('pn')
|
46
91
|
new_file.write(new_contents)
|