Skip to content

Instantly share code, notes, and snippets.

@hovsater
Last active January 8, 2021 22:11
Show Gist options
  • Save hovsater/eefc98c1e3ab9a471e24c6687726b081 to your computer and use it in GitHub Desktop.
Save hovsater/eefc98c1e3ab9a471e24c6687726b081 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'find'
require 'pathname'
BREWFILE_NAME = Pathname.new(File.expand_path("../Brewfile.all", __FILE__))
begin
brewfile = File.open(BREWFILE_NAME, "w")
home = Pathname.new(ENV['HOME'])
exclude_directories = %w(Desktop Documents Downloads Library Movies Music Pictures Public *node_modules *tmp */vendor/bundle)
Find.find(home) do |p|
is_dir = FileTest.directory?(p)
Find.prune if !FileTest.readable?(p) || File.basename(p).start_with?(".") || is_dir && exclude_directories.any? { |e| File.fnmatch?(e, Pathname.new(p).relative_path_from(home)) }
next if File.basename(p) != 'Brewfile'
puts "Writing #{Pathname.new(p).relative_path_from(home)} to #{BREWFILE_NAME.relative_path_from(home)}"
brewfile.puts File.read(p)
end
ensure
brewfile.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment