Skip to content

Instantly share code, notes, and snippets.

@micahbrich
Forked from cowboy/clone_fast.rb
Created July 3, 2011 17:38
Show Gist options
  • Save micahbrich/1062408 to your computer and use it in GitHub Desktop.
Save micahbrich/1062408 to your computer and use it in GitHub Desktop.
League Cloner
# /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 = "git@github.com:#{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}"
@micahbrich
Copy link
Author

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:

ruby cloner.rb

It'll clone all the fonts we have uploaded, skipping any that you've already cloned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment