Created
November 28, 2012 17:51
-
-
Save i-blis/4162855 to your computer and use it in GitHub Desktop.
Download gist files to current directory
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 | |
require 'github_api' | |
require 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.on("-a", "--add-gist-id", "Add gist ID to output filename") do |v| | |
options[:add] = true | |
end | |
opts.on("-q", "--quiet", "Run quietly") do |v| | |
options[:quiet] = true | |
end | |
end.parse! | |
ARGV.each do |gist_id| | |
gists = Github.gists.get gist_id | |
files = gists['files'] | |
files.each_key do |file| | |
filename = files[file]['filename'] | |
content = files[file]['content'] | |
if options[:add] | |
barename, suffix = filename.split /\.(\w+)$/ | |
filename = barename + "-#{gist_id}" + (suffix.nil? ? '' : ".#{suffix}") | |
end | |
File.open(filename, 'w') do |f| | |
puts "Writing #{filename}" unless options[:quiet] | |
f.write(content) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment