Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c3ced2a81a
Fetching contributors…

Cannot retrieve contributors at this time

executable file 68 lines (53 sloc) 1.893 kb
#!/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'json'
require 'grit'
require 'zip/zipfilesystem' # rubyzip gem
repos_dir = 'repos'
scripts_dir = 'scripts'
token = File.read('token').chomp
Dir.mkdir repos_dir unless test ?d, repos_dir
Dir.mkdir scripts_dir unless test ?d, scripts_dir
script = JSON.parse($stdin.read)
repo_path = File.join(repos_dir, script['name'] + '.git')
$repo_path = repo_path
repo = Grit::Repo.init_bare_or_open(repo_path)
def download(url, dest)
puts "Downloading #{url} to #{dest}"
open(url, 'rb') { |u|
File.open(dest, 'wb') { |f|
f.write(u.read)
}
}
end
def copy_file(filename, contents)
puts "Copying #{filename} into #{$repo_path}"
end
def copy_zip(zip_path)
Zip::ZipFile.open(zip_path) do |zipfile|
zipfile.each do |file|
raise "add symlinks!" if file.symlink?
copy_file(file.name, file.get_input_stream.read)
end
end
end
# github = Octopussy::Client.new(:login => 'vim-scripts', :token => token)
script['versions'].reverse.each do |version|
scriptname = "#{version['date']} #{version['script_version']} #{version['filename']}"
scriptdir = File.join(scripts_dir, script['name'])
Dir.mkdir scriptdir unless test ?d, scriptdir
scriptfile = File.join(scriptdir, scriptname)
download(version['url'], scriptfile) unless test ?f, scriptfile
# todo: might want to do a HEAD request and match file sizes
case scriptfile
when /\.vim$/ then copy_file(scriptfile, File.read(scriptfile))
when /\.zip$/ then copy_zip(scriptfile)
when /\.tar\.gz$|\.tgz$/ then puts "can't handle .tar.gz"
when /\.tar\.bz2?$|\.tbz2?$/ then puts "can't handle .tar.bz"
when /\.gz$/ then puts "can't handle .gz"
when /\.bz2?$/ then puts "can't handle .bz"
when /\.vba$/ then puts "can't handle .vba"
end
exit
end
Jump to Line
Something went wrong with that request. Please try again.