Skip to content

Instantly share code, notes, and snippets.

@aereal
Last active December 19, 2015 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aereal/da94aebcd5a28fd80685 to your computer and use it in GitHub Desktop.
Save aereal/da94aebcd5a28fd80685 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'pathname'
DEVEL_PATH = ENV['DEVEL_PATH']
HOMEBREW_ROOT = `brew --prefix`.strip
SRC_ROOT = File.join(DEVEL_PATH, 'src', 'github.com')
HOMEBREW_TAPS_ROOT = File.join(HOMEBREW_ROOT, 'Library', 'Taps')
class HomebrewTap
attr_reader :path
def initialize(path)
@path = Pathname.new(path.to_s)
end
def owner
@path.parent.basename.to_s
end
def name
@path.basename.to_s
end
def inspect
"<#{self.class}:#{self.owner}/#{self.name}>"
end
end
taps = Pathname.glob("#{HOMEBREW_TAPS_ROOT}/*/*").select(&:directory?).map {|path| HomebrewTap.new(path) }
src_path = Pathname.new(SRC_ROOT)
taps.each do |tap|
dest_parent = src_path.join(tap.owner)
dest_path = dest_parent.join(tap.name)
puts '-' * 25
puts "---> #{tap}"
if dest_path.exist?
puts "---> Skip"
else
puts "mkdir -p #{dest_parent}"
dest_parent.mkpath
puts "mv #{tap.path} #{dest_path}"
tap.path.rename(dest_path)
puts "ln -s #{dest_path} #{tap.path}"
tap.path.make_symlink(dest_path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment