gist_pull 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gist_pull +61 -0
- metadata +56 -0
data/bin/gist_pull
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
#grab a gist and put it down locally
|
4
|
+
#suggested .bash_profile alias: alias gist_pull='ruby /dir/to/gist_pull.rb'
|
5
|
+
|
6
|
+
require 'open-uri'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
def print_help
|
10
|
+
puts "gist_pull usage:"
|
11
|
+
puts " gist_pull\t\tshow this help dialog"
|
12
|
+
puts " gist_pull <gist id>\tfetches gist with id <gist id>\n\t\t\tif multiple files exists a choice is given via"
|
13
|
+
puts "\t\t\tprompt(:) and files should be listed on one line or 'all'"
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
print_help unless ARGV.length == 1
|
19
|
+
|
20
|
+
|
21
|
+
meta = ""
|
22
|
+
open("http://gist.github.com/api/v1/json/#{ARGV[0]}") { |f|
|
23
|
+
f.each_line {|line| meta << line }
|
24
|
+
}
|
25
|
+
|
26
|
+
meta = JSON.parse(meta)["gists"].first
|
27
|
+
files = meta['files']
|
28
|
+
#puts meta
|
29
|
+
|
30
|
+
def download(uri, name)
|
31
|
+
gist = open(uri).read
|
32
|
+
File.open(name, 'w') do |f|
|
33
|
+
f.puts gist
|
34
|
+
end
|
35
|
+
puts " saved as #{Dir.pwd}/#{name}."
|
36
|
+
end
|
37
|
+
|
38
|
+
if files.length == 1
|
39
|
+
file_name = files.first
|
40
|
+
uri = "https://gist.github.com/raw/#{ARGV[0]}/#{file_name}"
|
41
|
+
puts "downloading: #{uri}"
|
42
|
+
download(uri, file_name)
|
43
|
+
|
44
|
+
else
|
45
|
+
puts "∆! multiple files in this gist:\n"
|
46
|
+
files.each {|f| puts "\t #{f}"}
|
47
|
+
puts "Which do you want to download?"
|
48
|
+
print ': '
|
49
|
+
f = STDIN.gets.chomp
|
50
|
+
files_desired = f.sub(',',' ').split(' ')
|
51
|
+
if f == 'all'
|
52
|
+
files_desired = files
|
53
|
+
end
|
54
|
+
|
55
|
+
files.select!{ |f| files_desired.include? f}
|
56
|
+
puts "getting:"
|
57
|
+
files.each do |f|
|
58
|
+
puts " • #{f}"
|
59
|
+
download("https://gist.github.com/raw/#{ARGV[0]}/#{f}", f)
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gist_pull
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.2"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Artem Titoulenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-13 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email: artem.titoulenko@gmail.com
|
19
|
+
executables:
|
20
|
+
- gist_pull
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- bin/gist_pull
|
27
|
+
has_rdoc: true
|
28
|
+
homepage: https://github.com/ArtemTitoulenko
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project: nowarning
|
51
|
+
rubygems_version: 1.6.1
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: A tool that clones gists to your local directory
|
55
|
+
test_files: []
|
56
|
+
|