-
Notifications
You must be signed in to change notification settings - Fork 2
/
brew_not_installed
executable file
·99 lines (71 loc) · 1.76 KB
/
brew_not_installed
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
#!/usr/bin/env ruby
#
# SMELL: brew leaves is not reliable; or maybe
# it is being used the wrong way.
#
require 'amazing_print'
require 'debug_me'
include DebugMe
require 'pathname'
require 'set'
# TODO: Add some usage text
me = Pathname.new(__FILE__).realpath
my_name = me.basename
my_dir = me.parent
brewfile_name = 'Brewfile'
USAGE = <<~END_USAGE
Usage: #{my_name} [path_to_brewfile]
TODO: Add some usage text
END_USAGE
if ARGV.empty?
brewfile_path = Pathname.pwd + brewfile_name
else
bf_path = Pathname.new(ARGV.shift)
if bf_path.exist?
if bf_path.directory?
brewfile_path = bf_path + brewfile_name
unless brewfile_path.exist?
puts <<~ERROR
Error: File does not exist: #{brewfile_path}
ERROR
exit(-1)
end
else
brewfile_path = bf_path
end
else
puts <<~ERROR
Error: Pathgiven does not exist: #{bf_path}
ERROR
exit(-1)
end
end
installed = `brew leaves -r`.split("\n").map{|f| f.strip}.sort
bfh = Hash.new
brewfile_path.
read.
split("\n").
select{|a_line| !a_line.empty? && !a_line.start_with?('#')}.
each do |a_line|
key = a_line.split(' ').first.strip
bfh[key] = a_line
end
bfh_keys = bfh.keys.sort
installed_set = installed.to_set
not_installed_set = bfh_keys.to_set - installed_set
not_installed_set.each do |package|
puts "#{bfh[package]}"
end
puts "="*65
not_installed = (bfh_keys - installed)
ap not_installed
File.open('bfh_keys.txt', 'w').write bfh_keys.join("\n")
File.open('installed.txt', 'w').write installed.join("\n")
if ARGV.include? "--install"
puts "Installing ..."
not_installed.each_slice(5) do |group|
command = "brew install #{group.join(' ')}"
puts command
`#{command}`
end
end