gist 2.0.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -8,69 +8,80 @@ Installation
8
8
 
9
9
  [homebrew](http://mxcl.github.com/homebrew/):
10
10
 
11
- brew install gist
12
- gist -h
11
+ ```bash
12
+ $ brew install gist
13
+ $ gist -h
14
+ ```
13
15
 
14
16
  RubyGems:
15
17
 
16
- gem install gist
17
- gist -h
18
+ ```bash
19
+ $ gem install gist
20
+ $ gist -h
21
+ ```
18
22
 
19
23
  Old school:
20
24
 
21
- curl -s https://github.com/defunkt/gist/raw/master/gist > gist &&
22
- chmod 755 gist &&
23
- mv gist /usr/local/bin/gist
25
+ ```bash
26
+ $ curl -s https://raw.github.com/defunkt/gist/master/gist > gist &&
27
+ $ chmod 755 gist &&
28
+ $ mv gist /usr/local/bin/gist
29
+ ```
24
30
 
25
31
  Ubuntu:
26
32
 
27
- sudo apt-get install ruby
28
- sudo apt-get install rubygems
29
- sudo apt-get install libopenssl-ruby
30
- sudo gem install gist
31
- sudo cp /var/lib/gems/1.8/bin/gist /usr/local/bin/
32
- gist -h
33
-
34
-
33
+ ```bash
34
+ $ sudo apt-get install ruby
35
+ $ sudo apt-get install rubygems
36
+ $ sudo apt-get install libopenssl-ruby
37
+ $ sudo gem install gist
38
+ $ sudo cp /var/lib/gems/1.8/bin/gist /usr/local/bin/
39
+ $ gist -h
40
+ ```
35
41
 
36
42
  Use
37
43
  ---
38
44
 
39
- $ gist < file.txt
40
- $ echo secret | gist --private # or -p
41
- $ echo "puts :hi" | gist -t rb
42
- $ gist script.py
43
- $ gist script.js notes.txt
44
- $ gist -
45
- the quick brown fox jumps over the lazy dog
46
- ^D
47
-
45
+ ```bash
46
+ $ gist < file.txt
47
+ $ echo secret | gist --private # or -p
48
+ $ echo "puts :hi" | gist -t rb
49
+ $ gist script.py
50
+ $ gist script.js notes.txt
51
+ $ pbpaste | gist -p # Copy from clipboard - OSX Only
52
+ $ gist -
53
+ the quick brown fox jumps over the lazy dog
54
+ ^D
55
+ ```
48
56
 
49
57
  Authentication
50
58
  --------------
51
- There are two ways to set GitHub user and token info:
59
+ There are two ways to set GitHub user and password info:
52
60
 
53
- Using env vars GITHUB_USER and GITHUB_TOKEN:
61
+ Using env vars GITHUB_USER and GITHUB_PASSWORD:
54
62
 
55
- $ export GITHUB_USER="your-github-username"
56
- $ export GITHUB_TOKEN="your-github-token"
57
- $ gist ~/example
63
+ ```bash
64
+ $ export GITHUB_USER="your-github-username"
65
+ $ export GITHUB_PASSWORD="your-github-password"
66
+ $ gist ~/example
67
+ ```
58
68
 
59
- Or by having your git config set up with your GitHub username and token.
69
+ Or by having your git config set up with your GitHub username and password.
60
70
 
61
- git config --global github.user "your-github-username"
62
- git config --global github.token "your-github-token"
71
+ ```bash
72
+ git config --global github.user "your-github-username"
73
+ git config --global github.password "your-github-password"
74
+ ```
63
75
 
64
- You can find your token under [your account](https://github.com/account).
65
-
66
- You can also define github.token to be a command which returns the
67
- actual token on stdout by setting the variable to a command string
76
+ You can also define github.password to be a command which returns the
77
+ actual password on stdout by setting the variable to a command string
68
78
  prefixed with `!`. For example, the following command fetches the
69
- token from a password item named "github.token" on the Mac OS
79
+ password from an item named "github.password" on the Mac OS
70
80
  Keychain:
71
81
 
72
- token = !security 2>&1 >/dev/null find-generic-password -gs github.token | ruby -e 'print $1 if STDIN.gets =~ /^password: \\\"(.*)\\\"$/'
73
-
82
+ ```bash
83
+ password = !security 2>&1 >/dev/null find-generic-password -gs github.password | ruby -e 'print $1 if STDIN.gets =~ /^password: \\\"(.*)\\\"$/'
84
+ ```
74
85
 
75
86
  Defaults
76
87
  --------
@@ -91,15 +102,18 @@ Proxies
91
102
 
92
103
  Set the HTTP_PROXY env variable to use a proxy.
93
104
 
94
- $ HTTP_PROXY=host:port gist file.rb
95
-
105
+ ```bash
106
+ $ HTTP_PROXY=host:port gist file.rb
107
+ ```
96
108
 
97
109
  Manual
98
110
  ------
99
111
 
100
112
  Visit <http://defunkt.github.com/gist/> or use:
101
113
 
102
- $ gist -m
114
+ ```bash
115
+ $ gist -m
116
+ ```
103
117
 
104
118
  Bugs
105
119
  ----
data/Rakefile CHANGED
@@ -1,4 +1,9 @@
1
- require 'bundler/gem_tasks'
1
+ begin
2
+ require "mg"
3
+ MG.new("gist.gemspec")
4
+ rescue LoadError
5
+ nil
6
+ end
2
7
 
3
8
  desc "Build standalone script and manpages"
4
9
  task :build => [ :standalone, :build_man ]
@@ -23,3 +28,24 @@ task :load_gist do
23
28
  $LOAD_PATH.unshift 'lib'
24
29
  require 'gist'
25
30
  end
31
+
32
+ Rake::TaskManager.class_eval do
33
+ def remove_task(task_name)
34
+ @tasks.delete(task_name.to_s)
35
+ end
36
+ end
37
+
38
+ # Remove mg's install task
39
+ Rake.application.remove_task(:install)
40
+
41
+ desc "Install standalone script and man pages"
42
+ task :install => :standalone do
43
+ prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
44
+
45
+ FileUtils.mkdir_p "#{prefix}/bin"
46
+ FileUtils.cp "gist", "#{prefix}/bin"
47
+
48
+ FileUtils.mkdir_p "#{prefix}/share/man/man1"
49
+ FileUtils.cp "man/gist.1", "#{prefix}/share/man/man1"
50
+ end
51
+
data/lib/gist.rb CHANGED
@@ -2,6 +2,10 @@ require 'open-uri'
2
2
  require 'net/https'
3
3
  require 'optparse'
4
4
 
5
+ require 'rubygems'
6
+ require 'json'
7
+ require 'base64'
8
+
5
9
  require 'gist/manpage' unless defined?(Gist::Manpage)
6
10
  require 'gist/version' unless defined?(Gist::Version)
7
11
 
@@ -23,8 +27,8 @@ require 'gist/version' unless defined?(Gist::Version)
23
27
  module Gist
24
28
  extend self
25
29
 
26
- GIST_URL = 'https://gist.github.com/%s.txt'
27
- CREATE_URL = 'https://gist.github.com/gists'
30
+ GIST_URL = 'https://api.github.com/gists/%s'
31
+ CREATE_URL = 'https://api.github.com/gists'
28
32
 
29
33
  if ENV['HTTPS_PROXY']
30
34
  PROXY = URI(ENV['HTTPS_PROXY'])
@@ -42,6 +46,7 @@ module Gist
42
46
  gist_filename = nil
43
47
  gist_extension = defaults["extension"]
44
48
  browse_enabled = defaults["browse"]
49
+ description = nil
45
50
 
46
51
  opts = OptionParser.new do |opts|
47
52
  opts.banner = "Usage: gist [options] [filename or stdin] [filename] ...\n" +
@@ -56,6 +61,10 @@ module Gist
56
61
  gist_extension = '.' + extension
57
62
  end
58
63
 
64
+ opts.on('-d','--description DESCRIPTION', 'Set description of the new gist') do |d|
65
+ description = d
66
+ end
67
+
59
68
  opts.on('-o','--[no-]open', 'Open gist in browser') do |o|
60
69
  browse_enabled = o
61
70
  end
@@ -75,9 +84,10 @@ module Gist
75
84
  end
76
85
  end
77
86
 
78
- opts.parse!(args)
79
-
80
87
  begin
88
+
89
+ opts.parse!(args)
90
+
81
91
  if $stdin.tty? && args[0] != '-'
82
92
  # Run without stdin.
83
93
 
@@ -93,7 +103,7 @@ module Gist
93
103
 
94
104
  files.push({
95
105
  :input => File.read(file),
96
- :filename => File.basename(file),
106
+ :filename => file,
97
107
  :extension => (File.extname(file) if file.include?('.'))
98
108
  })
99
109
  end
@@ -104,7 +114,7 @@ module Gist
104
114
  files = [{:input => input, :extension => gist_extension}]
105
115
  end
106
116
 
107
- url = write(files, private_gist)
117
+ url = write(files, private_gist, description)
108
118
  browse(url) if browse_enabled
109
119
  puts copy(url)
110
120
  rescue => e
@@ -114,7 +124,7 @@ module Gist
114
124
  end
115
125
 
116
126
  # Create a gist on gist.github.com
117
- def write(files, private_gist = false)
127
+ def write(files, private_gist = false, description = nil)
118
128
  url = URI.parse(CREATE_URL)
119
129
 
120
130
  if PROXY_HOST
@@ -129,12 +139,16 @@ module Gist
129
139
  http.ca_file = ca_cert
130
140
 
131
141
  req = Net::HTTP::Post.new(url.path)
132
- req.form_data = data(files, private_gist)
142
+ req.body = JSON.generate(data(files, private_gist, description))
143
+
144
+ if auth_header = auth()
145
+ req.add_field('Authorization', auth_header)
146
+ end
133
147
 
134
148
  response = http.start{|h| h.request(req) }
135
149
  case response
136
- when Net::HTTPRedirection
137
- response['Location']
150
+ when Net::HTTPCreated
151
+ JSON.parse(response.body)['html_url']
138
152
  else
139
153
  puts "Creating gist failed: #{response.code} #{response.message}"
140
154
  exit(false)
@@ -143,7 +157,8 @@ module Gist
143
157
 
144
158
  # Given a gist id, returns its content.
145
159
  def read(gist_id)
146
- open(GIST_URL % gist_id).read
160
+ data = JSON.parse(open(GIST_URL % gist_id).read)
161
+ data["files"].map{|name, content| content['content'] }.join("\n\n")
147
162
  end
148
163
 
149
164
  # Given a url, tries to open it in your browser.
@@ -151,6 +166,8 @@ module Gist
151
166
  def browse(url)
152
167
  if RUBY_PLATFORM =~ /darwin/
153
168
  `open #{url}`
169
+ elsif RUBY_PLATFORM =~ /linux/
170
+ `#{ENV['BROWSER']} #{url}`
154
171
  elsif ENV['OS'] == 'Windows_NT' or
155
172
  RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw|wince/i
156
173
  `start "" "#{url}"`
@@ -178,27 +195,32 @@ module Gist
178
195
  private
179
196
  # Give an array of file information and private boolean, returns
180
197
  # an appropriate payload for POSTing to gist.github.com
181
- def data(files, private_gist)
182
- data = {}
198
+ def data(files, private_gist, description)
199
+ i = 0
200
+ file_data = {}
183
201
  files.each do |file|
184
- i = data.size + 1
185
- data["file_ext[gistfile#{i}]"] = file[:extension] ? file[:extension] : '.txt'
186
- data["file_name[gistfile#{i}]"] = file[:filename]
187
- data["file_contents[gistfile#{i}]"] = file[:input]
202
+ i = i + 1
203
+ filename = file[:filename] ? file[:filename] : "gistfile#{i}"
204
+ file_data[filename] = {:content => file[:input]}
188
205
  end
189
- data.merge(private_gist ? { 'action_button' => 'private' } : {}).merge(auth)
206
+
207
+ data = {"files" => file_data}
208
+ data.merge!({ 'description' => description }) unless description.nil?
209
+ data.merge!({ 'public' => false }) if private_gist
210
+ data
190
211
  end
191
212
 
192
- # Returns a hash of the user's GitHub credentials if set.
213
+ # Returns a basic auth string of the user's GitHub credentials if set.
193
214
  # http://github.com/guides/local-github-config
194
215
  def auth
195
216
  user = config("github.user")
196
- token = config("github.token")
217
+ password = config("github.password")
197
218
 
198
- if user.to_s.empty? || token.to_s.empty?
199
- {}
219
+ if user.to_s.empty? || password.to_s.empty?
220
+ nil
200
221
  else
201
- { :login => user, :token => token }
222
+ auth_str = Base64.encode64("#{user}:#{password}")
223
+ "Basic #{auth_str}"
202
224
  end
203
225
  end
204
226
 
@@ -211,24 +233,23 @@ private
211
233
  # gist.extension - string
212
234
  def defaults
213
235
  extension = config("gist.extension")
214
- extension = nil if extension && extension.empty?
215
236
 
216
237
  return {
217
238
  "private" => config("gist.private"),
218
239
  "browse" => config("gist.browse"),
219
- "extension" => extension,
240
+ "extension" => extension
220
241
  }
221
242
  end
222
243
 
223
244
  # Reads a config value using:
224
- # => Environement: GITHUB_TOKEN, GITHUB_USER
225
- # like vim gist plugin
245
+ # => Environment: GITHUB_PASSWORD, GITHUB_USER
246
+ # like vim gist plugin
226
247
  # => git-config(1)
227
248
  #
228
249
  # return something useful or nil
229
250
  def config(key)
230
251
  env_key = ENV[key.upcase.gsub(/\./, '_')]
231
- return env_key if env_key and not env_key.empty?
252
+ return env_key if env_key and not env_key.strip.empty?
232
253
 
233
254
  str_to_bool `git config --global #{key}`.strip
234
255
  end
data/lib/gist/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gist
2
- VERSION = Version = '2.0.4'
2
+ VERSION = Version = '3.0.0'
3
3
  end
data/man/gist.1 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "GIST" "1" "April 2011" "GITHUB" "Gist Manual"
4
+ .TH "GIST" "1" "March 2012" "GITHUB" "Gist Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBgist\fR \- gist on the command line
@@ -19,7 +19,7 @@ If standard input is supplied, it will be used as the content of the new gist\.
19
19
  Once your gist is successfully created, the URL will be copied to your clipboard\. If you are on OS X, \fBgist\fR will open the gist in your browser, too\.
20
20
  .
21
21
  .SH "OPTIONS"
22
- \fBgist\fR\'s default mode of operation is to read content from standard input and create a public, text gist from it, tied to your GitHub account if you user and token are provided (see \fBCONFIGURATION\fR)\.
22
+ \fBgist\fR\'s default mode of operation is to read content from standard input and create a public, text gist without description from it, tied to your GitHub account if you user and passwordare provided (see \fBCONFIGURATION\fR)\.
23
23
  .
24
24
  .P
25
25
  These options can be used to change this behavior:
@@ -30,7 +30,11 @@ Create a private gist instead of a public gist\.
30
30
  .
31
31
  .TP
32
32
  \fB\-t\fR, \fB\-\-type\fR
33
- Set the file extension explicitly\. Passing a type of \fBrb\fR ensure the gist is created as a Ruby file\.
33
+ Set the file extension explicitly\. Passing a type of \fBrb\fR ensures the gist is created as a Ruby file\.
34
+ .
35
+ .TP
36
+ \fB\-d\fR, \fB\-\-description\fR
37
+ Set a description\.
34
38
  .
35
39
  .TP
36
40
  \fB\-o\fR, \fB\-\-[no\-]open\fR
@@ -48,16 +52,16 @@ Print help\.
48
52
  Display this man page\.
49
53
  .
50
54
  .SH "AUTHENTICATION"
51
- There are two ways to set GitHub user and token info:
55
+ There are two ways to set GitHub user and password info:
52
56
  .
53
57
  .IP "\(bu" 4
54
- Using env vars GITHUB_USER and GITHUB_TOKEN
58
+ Using environment vars GITHUB_USER and GITHUB_PASSWORD
55
59
  .
56
60
  .IP
57
61
  $ export GITHUB_USER=johndoe
58
62
  .
59
63
  .br
60
- $ export GITHUB_TOKEN=mysecretgithubtoken
64
+ $ export GITHUB_PASSWORD=mysecretgithubpassword
61
65
  .
62
66
  .br
63
67
  $ gist ~/example
data/man/gist.1.html CHANGED
@@ -64,7 +64,7 @@
64
64
  <a href="#BUGS">BUGS</a>
65
65
  <a href="#AUTHOR">AUTHOR</a>
66
66
  <a href="#SEE-ALSO">SEE ALSO</a>
67
- </div>
67
+ </div>
68
68
 
69
69
  <ol class='man-decor man-head man head'>
70
70
  <li class='tl'>gist(1)</li>
@@ -98,15 +98,17 @@ browser, too.</p>
98
98
  <h2 id="OPTIONS">OPTIONS</h2>
99
99
 
100
100
  <p><code>gist</code>'s default mode of operation is to read content from standard
101
- input and create a public, text gist from it, tied to your GitHub
102
- account if you user and token are provided (see <code>CONFIGURATION</code>).</p>
101
+ input and create a public, text gist without description from it, tied
102
+ to your GitHub account if you user and passwordare provided (see
103
+ <code>CONFIGURATION</code>).</p>
103
104
 
104
105
  <p>These options can be used to change this behavior:</p>
105
106
 
106
107
  <dl>
107
108
  <dt><code>-p</code>, <code>--private</code></dt><dd><p>Create a private gist instead of a public gist.</p></dd>
108
- <dt><code>-t</code>, <code>--type</code></dt><dd><p>Set the file extension explicitly. Passing a type of <code>rb</code> ensure
109
+ <dt><code>-t</code>, <code>--type</code></dt><dd><p>Set the file extension explicitly. Passing a type of <code>rb</code> ensures
109
110
  the gist is created as a Ruby file.</p></dd>
111
+ <dt><code>-d</code>, <code>--description</code></dt><dd><p>Set a description.</p></dd>
110
112
  <dt><code>-o</code>, <code>--[no-]open</code></dt><dd><p>Open the gist in your browser after creation. Or don't. Defaults
111
113
  to --open</p></dd>
112
114
  </dl>
@@ -122,13 +124,13 @@ to --open</p></dd>
122
124
 
123
125
  <h2 id="AUTHENTICATION">AUTHENTICATION</h2>
124
126
 
125
- <p>There are two ways to set GitHub user and token info:</p>
127
+ <p>There are two ways to set GitHub user and password info:</p>
126
128
 
127
129
  <ul>
128
- <li><p>Using env vars GITHUB_USER and GITHUB_TOKEN</p>
130
+ <li><p>Using environment vars GITHUB_USER and GITHUB_PASSWORD</p>
129
131
 
130
132
  <p>$ export GITHUB_USER=johndoe<br />
131
- $ export GITHUB_TOKEN=mysecretgithubtoken<br />
133
+ $ export GITHUB_PASSWORD=mysecretgithubpassword<br />
132
134
  $ gist ~/example</p></li>
133
135
  <li><p>Using <span class="man-ref">git-config<span class="s">(1)</span></span></p></li>
134
136
  </ul>
@@ -198,7 +200,7 @@ the quick brown fox jumps over the lazy dog
198
200
 
199
201
  <ol class='man-decor man-foot man foot'>
200
202
  <li class='tl'>GITHUB</li>
201
- <li class='tc'>April 2011</li>
203
+ <li class='tc'>March 2012</li>
202
204
  <li class='tr'>gist(1)</li>
203
205
  </ol>
204
206
 
data/man/gist.1.ron CHANGED
@@ -22,8 +22,9 @@ browser, too.
22
22
  ## OPTIONS
23
23
 
24
24
  `gist`'s default mode of operation is to read content from standard
25
- input and create a public, text gist from it, tied to your GitHub
26
- account if you user and token are provided (see `CONFIGURATION`).
25
+ input and create a public, text gist without description from it, tied
26
+ to your GitHub account if you user and passwordare provided (see
27
+ `CONFIGURATION`).
27
28
 
28
29
  These options can be used to change this behavior:
29
30
 
@@ -31,9 +32,12 @@ These options can be used to change this behavior:
31
32
  Create a private gist instead of a public gist.
32
33
 
33
34
  * `-t`, `--type`:
34
- Set the file extension explicitly. Passing a type of `rb` ensure
35
+ Set the file extension explicitly. Passing a type of `rb` ensures
35
36
  the gist is created as a Ruby file.
36
37
 
38
+ * `-d`, `--description`:
39
+ Set a description.
40
+
37
41
  * `-o`, `--[no-]open`:
38
42
  Open the gist in your browser after creation. Or don't. Defaults
39
43
  to --open
@@ -48,12 +52,12 @@ You may additionally ask for help:
48
52
 
49
53
  ## AUTHENTICATION
50
54
 
51
- There are two ways to set GitHub user and token info:
55
+ There are two ways to set GitHub user and password info:
52
56
 
53
- * Using env vars GITHUB_USER and GITHUB_TOKEN
57
+ * Using environment vars GITHUB_USER and GITHUB_PASSWORD
54
58
 
55
59
  $ export GITHUB_USER=johndoe
56
- $ export GITHUB_TOKEN=mysecretgithubtoken
60
+ $ export GITHUB_PASSWORD=mysecretgithubpassword
57
61
  $ gist ~/example
58
62
 
59
63
  * Using git-config(1)
metadata CHANGED
@@ -2,12 +2,12 @@
2
2
  name: gist
3
3
  version: !ruby/object:Gem::Version
4
4
  hash: 7
5
- prerelease: false
5
+ prerelease:
6
6
  segments:
7
- - 2
7
+ - 3
8
8
  - 0
9
- - 4
10
- version: 2.0.4
9
+ - 0
10
+ version: 3.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Wanstrath
@@ -16,25 +16,10 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-27 00:00:00 -07:00
19
+ date: 2012-03-20 00:00:00 -07:00
20
20
  default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- name: bundler
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 11
31
- segments:
32
- - 1
33
- - 0
34
- - 14
35
- version: 1.0.14
36
- type: :development
37
- version_requirements: *id001
21
+ dependencies: []
22
+
38
23
  description: " Creates Gists (pastes) on gist.github.com from standard input or\n arbitrary files. Can link to your GitHub account, create private gists,\n and enable syntax highlighting.\n"
39
24
  email: andre@arko.net
40
25
  executables:
@@ -56,7 +41,7 @@ files:
56
41
  - man/gist.1
57
42
  - man/gist.1.html
58
43
  - man/gist.1.ron
59
- has_rdoc: false
44
+ has_rdoc: true
60
45
  homepage: http://github.com/defunkt/gist
61
46
  licenses: []
62
47
 
@@ -86,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
71
  requirements: []
87
72
 
88
73
  rubyforge_project:
89
- rubygems_version: 1.3.7
74
+ rubygems_version: 1.6.2
90
75
  signing_key:
91
76
  specification_version: 3
92
77
  summary: Creates Gists from STDIN or files.