gistribute 0.0.1.pre1 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README.md +52 -1
  2. data/VERSION +1 -0
  3. data/bin/gistribute +25 -11
  4. data/gistribute.gemspec +1 -1
  5. metadata +5 -4
data/README.md CHANGED
@@ -2,4 +2,55 @@
2
2
 
3
3
  Gistribute is a simple file distribution system based on GitHub's Gist service.
4
4
 
5
- More coming soon.
5
+ I decided to make Gistribute when I found myself sharing configuration files
6
+ and such with others by placing all of them into a Gist along with a little
7
+ Bash script that curled all of the files, via their raw URLs, to the right
8
+ location on the other's computer. This program removed the need to make that
9
+ script, and the need to update the raw URLs in that script whenever you make
10
+ a tweak to one of the files that you're sharing.
11
+
12
+ ## Installation
13
+
14
+ $ gem install gistribute
15
+
16
+ ## How It Works
17
+
18
+ Gistribute looks at the files in each Gist and checks for one or two lines of
19
+ metadata at the top of the file. The metadata must begin with ```%%```, but
20
+ you may put anything before that and it won't be parsed.
21
+
22
+ The first line of metadata contains the location on the client's computer that
23
+ you wish to install the file to. The second contains the name of the file as it
24
+ will be printed on the user's screen as it is installed. If the second line is
25
+ excluded, Gistribute will use the name of the file in the Gist.
26
+
27
+ ## Usage
28
+
29
+ An example follows:
30
+
31
+ ```VimL
32
+ "%% ~/.vimrc
33
+ "%% Vim configuration
34
+ " This is an example .vimrc file being shared via Gistribute.
35
+ " Notice the two comments at the top containing the metadata.
36
+
37
+ set nocompatible
38
+ filetype indent plugin on
39
+ syntax on
40
+ ```
41
+
42
+ If, for example, the resulting Gist link was https://gist.github.com/123456,
43
+ the user would be able to run either of these commands to download the file
44
+ to ```~/.vimrc```:
45
+
46
+ $ gistribute 123456
47
+ $ gistribute https://gist.github.com/123456
48
+
49
+ **Gistribute will strip the metadata from the files.** Don't worry about having
50
+ messy files on the user's computer because of the metadata sitting at the top,
51
+ as this is taken care of. Be aware, however, that if you leave a blank line
52
+ between the metadata and the first line of the file, the resulting downloaded
53
+ file **will** have a blank line at the top.
54
+
55
+ If there are files in the Gist without metadata, they will be ignored by
56
+ Gistribute.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/gistribute CHANGED
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ if %w[-v --version].include? ARGV.first
4
+ puts "Gistribute #{File.read(File.expand_path("../../VERSION", __FILE__)).strip}"
5
+ exit 0
6
+ end
7
+
3
8
  require "json"
4
9
  require "open-uri"
5
10
  require "colorize"
@@ -7,19 +12,23 @@ require "nutella"
7
12
 
8
13
  print "Downloading data..."
9
14
 
15
+ # The user can paste in either just the ID or the entire URL to the Gist.
16
+ id = ARGV.first[/(^|\/)([[:xdigit:]]+)/, 2]
17
+
10
18
  begin
11
- # TODO: Let the user paste the entire Gist URL and parse out the ID.
12
- gist = JSON.parse open("https://api.github.com/gists/#{ARGV.first}").read
19
+ gist = JSON.parse open("https://api.github.com/gists/#{id}").read
13
20
  rescue OpenURI::HTTPError => msg
14
- puts <<-EOS.heredoc.red
21
+ print <<-EOS.heredoc.red
15
22
 
16
23
 
17
24
  There was an error downloading the requested Gist.
18
25
  The error is as follows:
19
26
  EOS
20
-
21
27
  puts msg
22
28
 
29
+ puts "The ID that was queried is:".red
30
+ puts id
31
+
23
32
  exit -1
24
33
  end
25
34
 
@@ -43,19 +52,19 @@ end
43
52
  # }
44
53
  # }
45
54
 
46
- user = gist["user"] ? "user #{gist["user"]["login"]}" : "an anonymous user"
47
-
48
55
  puts <<-EOS.heredoc
49
56
 
50
57
 
51
58
  Finished downloading Gist from: #{gist["html_url"]}
52
- Gist uploaded by #{user}.
59
+ Gist uploaded by #{
60
+ gist["user"] ? "user #{gist["user"]["login"]}" : "an anonymous user"
61
+ }.
53
62
 
54
63
  Beginning install...
55
64
  EOS
56
65
 
57
66
  gist["files"].each do |filename, data|
58
- lines = data["content"].split "\n"
67
+ lines = data["content"].lines.to_a
59
68
 
60
69
  # Parse out all metadata after %% on the first two lines, strip out
61
70
  # (lead|trail)ing whitespace while we're at it.
@@ -66,10 +75,15 @@ gist["files"].each do |filename, data|
66
75
 
67
76
  puts " #{"*".green} Installing #{metadata[1] || filename}..."
68
77
 
69
- # TODO: Handle ~ better. Also, handle EOF newlines.
70
- File.open(metadata.first.gsub(/~/, Dir.home), "w") do |f|
78
+ # TODO: Is there a better way to handle ~?
79
+ path = metadata.first.gsub "~", Dir.home
80
+
81
+ # Handle directories that don't exist.
82
+ FileUtils.mkdir_p File.dirname(path)
83
+
84
+ File.open(path, "w") do |f|
71
85
  # Remove all lines with metadata- lines that don't match will return nil,
72
86
  # so compact it and drop that many off the top of the file.
73
- f << lines[metadata.compact.size..-1].join("\n")
87
+ f << lines[metadata.compact.size..-1].join
74
88
  end
75
89
  end
data/gistribute.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.executables = %w[gistribute]
16
16
 
17
17
  gem.files = Dir["bin/**/*"] + %w[
18
- LICENSE Rakefile README.md gistribute.gemspec
18
+ LICENSE Rakefile README.md VERSION gistribute.gemspec
19
19
  ]
20
20
 
21
21
  gem.add_dependency "json", "~> 1.7"
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gistribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre1
5
- prerelease: 6
4
+ version: 0.0.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Vinny Diehl
@@ -70,6 +70,7 @@ files:
70
70
  - LICENSE
71
71
  - Rakefile
72
72
  - README.md
73
+ - VERSION
73
74
  - gistribute.gemspec
74
75
  homepage: https://github.com/gbchaosmaster/gistribute
75
76
  licenses:
@@ -87,9 +88,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
88
  required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  none: false
89
90
  requirements:
90
- - - ! '>'
91
+ - - ! '>='
91
92
  - !ruby/object:Gem::Version
92
- version: 1.3.1
93
+ version: '0'
93
94
  requirements: []
94
95
  rubyforge_project:
95
96
  rubygems_version: 1.8.24