Last active
October 3, 2017 19:11
-
-
Save Demonstrandum/9e7a7bd474648089bad0aff721253171 to your computer and use it in GitHub Desktop.
Clone all GitHub Repos
This file contains hidden or 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 | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
raise ArgumentError, 'Expected at least 1 CLI argument!' if ARGV.empty? | |
root = user = String.new | |
%w{ git Git GitHub github repos }.each do |folder| | |
home = "#{File.expand_path '~'}/#{folder}" | |
if File.directory? home | |
root = home | |
break | |
end | |
end | |
ARGV.each { |arg| root = arg if File.directory? arg } | |
user = (ARGV - [root]).first | |
uri = URI.parse "https://api.github.com/users/#{user}/repos?per_page=999" | |
response = Net::HTTP.get_response uri | |
json = JSON.parse response.body | |
json.each do |repo| | |
puts %x{ git clone #{repo['ssh_url']} #{"#{root}/#{repo['name']}"} 2>&1 } | |
puts "Done!\n " | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation, copy this to your terminal:
Then you can run
clone-all MyGithubUsername ~/MyFolderToBeFullOfGitRepos
from anywhere.