Skip to content

Instantly share code, notes, and snippets.

@cobyism
Last active December 14, 2019 09:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cobyism/29b789d5a5be9f1d54da to your computer and use it in GitHub Desktop.
Save cobyism/29b789d5a5be9f1d54da to your computer and use it in GitHub Desktop.
Search /Applications for apps that can be installed with `brew cask` (see http://caskroom.io)
#!/usr/bin/env ruby
exact_matches = {}
partial_matches = {}
no_matches = []
puts "Searching /Applications for things that exist in cask…"
Dir.glob('/Applications/*.app').each do |app|
app_name = File.basename(app)
search_term = File.basename(app, ".*").downcase.split(/\s/)[0]
output = `brew cask search #{search_term}`
if output.match /Exact match/
exact_matches[app_name] = search_term
elsif output.match /Partial match/
partial_matches[app_name] = output.lines[1..-1].map(&:chomp)
else
no_matches.push app_name
end
end
puts "\nExact matches:\n"
exact_matches.each do |app, term|
puts term
end
puts "\nPartial matches:\n"
partial_matches.each do |app, terms|
puts "\nMatches for #{app}:\n"
terms.each do |term|
puts term
end
end
puts "\nNo matches:\n"
no_matches.each do |app|
puts app
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment