-
-
Save micahbrich/1062408 to your computer and use it in GitHub Desktop.
League Cloner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /usr/bin/env ruby | |
puts <<-EOF | |
LEAGUE CLONER via The League of Moveable Type | |
==================================================== | |
EOF | |
copyright = <<-EOF | |
==================================================== | |
Forked by micah rich for The League of Moveable Type | |
Original Script | |
https://gist.github.com/916434 | |
Copyright (c) 2011 "Cowboy" Ben Alman, http://benalman.com/ | |
Dual licensed under the MIT and GPL licenses. | |
http://benalman.com/about/license/ | |
EOF | |
# Handle ctrl-c abort. | |
trap('INT') do | |
puts "\nAborted!" | |
exit 1 | |
end | |
require 'open-uri' | |
require 'json' | |
require 'fileutils' | |
user = "theleagueof" | |
# Fetch and parse user JSON. | |
print "\n\nFetching repository list... " | |
json = open("http://github.com/api/v1/json/#{user}").read | |
data = JSON.parse(json) | |
# Create an array of filters from command line arguments, converting wildcard | |
# * and ? chars to their regex equivalent. | |
filters = ARGV.map do |a| | |
Regexp.new('^' + Regexp.escape(a).gsub(/\\\*/, '.*').gsub(/\\\?/, '.') + '$') | |
end | |
# If args were passed, filter out any repos whose names don't match any of the | |
# passed args. | |
repos = data['user']['repositories'].select do |r| | |
filters.empty? || filters.find {|re| r['name'] =~ re} | |
!["licenses", "the-typelog"].include?(r['name']) | |
end.compact | |
# No matching repos? FAIL. | |
if repos.empty? | |
puts "No repos found, exiting!" | |
exit 1 | |
end | |
puts "#{repos.length} repo#{repos.length == 1 ? '' : 's'} found.\n\n" | |
# Clone all matching repos that haven't already been cloned. | |
repos.each do |r| | |
path = (r['fork'] ? 'forks/' : '') + r['name'] | |
uri = "[email protected]:#{user}/#{r['name']}.git" | |
if File.exist?(path) | |
puts "Skipping #{path} (clone already exists).\n" | |
else | |
unless system %Q{git clone "#{uri}" "#{path}"} | |
# Cleanup potentially broken git clone. | |
FileUtils.rm_rf path | |
puts "\nAn error or abort ocurred!" | |
exit 1 | |
end | |
end | |
end | |
puts "\nDone!" | |
puts "\n\n #{copyright}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clone all the repos The League has on Github!
Download the script, move to the folder you'd like all the fonts in, open Terminal, & run:
It'll clone all the fonts we have uploaded, skipping any that you've already cloned.