gist 4.6.1 → 4.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -1
  3. data/bin/gist +11 -2
  4. data/build/gist +32 -6
  5. data/build/gist.1 +21 -2
  6. data/lib/gist.rb +21 -4
  7. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f19484015dcf7461d0498fa37013e616aec23b4
4
- data.tar.gz: e8784bc46d7261281acb0c947c8670c01588399a
3
+ metadata.gz: 8dcb4ad16178e41476596aa05e8819ed3431e5f2
4
+ data.tar.gz: 6698bd0bda9e583700e5bec695d7e6b5c1b6fba5
5
5
  SHA512:
6
- metadata.gz: 3307a3891b8fc1d302ba15092ca165ec72dbeb773c0ca4f47a6a079716747864b475410192fd8a5f8afcff06e78378c414a1d39641c8421e2dd4d1c244a4faba
7
- data.tar.gz: 865d65b608b91d4c258215e6d4e8b6af6278d2e78c0d368d66dcee146e69fd0fd293fe63f7031f273c177d259ac1cc3d5e713684b13dd1632d84a7442cede8b2
6
+ metadata.gz: 7ca4af1b0e24281a929ea6a39e5e67a3b2a2c5bc7aed06039adac829665f5e5d013061a65b097a3be0a68bc623c43299f5f9b148b2a28113644aff267cd86036
7
+ data.tar.gz: c4bde01c49fe0182422071f8afa445b3da2af1d829b7d4f36df957eef059ddb097f4e248f232c5bebf06888e22327d7b44bb18f93cb2456965f9f03e8f031f32
data/README.md CHANGED
@@ -98,6 +98,19 @@ file.
98
98
 
99
99
  gist -a a.rb
100
100
 
101
+ #### Password-less login
102
+
103
+ If you have a complicated authorization requirement you can manually create a
104
+ token file by pasting a Github token with only the `gist` permission into a
105
+ file called `~/.gist`. You can create one from https://github.com/settings/tokens
106
+
107
+ This file should contain only the token (~40 hex characters), and to make it
108
+ easier to edit, can optionally have a final newline (\n or \r\n).
109
+
110
+ For example, one way to create this file would be to run:
111
+
112
+ echo MY_SECRET_TOKEN > ~/.gist
113
+
101
114
  ### GitHub Enterprise
102
115
 
103
116
  If you'd like `gist` to use your locally installed [GitHub Enterprise](https://enterprise.github.com/),
@@ -109,7 +122,7 @@ Once you've done this and restarted your terminal (or run `source ~/.bashrc`), g
109
122
  automatically use github enterprise instead of the public github.com
110
123
 
111
124
  Your token for GitHub Enterprise will be stored in `.gist.<protocol>.<server.name>[.<port>]` (e.g.
112
- `~.gist.http.github.internal.example.com` for the GITHUB_URL example above) instead of `~/.gist`.
125
+ `~/.gist.http.github.internal.example.com` for the GITHUB_URL example above) instead of `~/.gist`.
113
126
 
114
127
  If you have multiple servers or use Enterprise and public GitHub often, you can work around this by creating scripts
115
128
  that set the env var and then run `gist`. Keep in mind that to use the public GitHub you must unset the env var. Just
data/bin/gist CHANGED
@@ -47,7 +47,11 @@ Instead of creating a new gist, you can update an existing one by passing its ID
47
47
  or URL with "-u". For this to work, you must be logged in, and have created the
48
48
  original gist with the same GitHub account.
49
49
 
50
- Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
50
+ If you want to skip empty files, use the --skip-empty flag. If all files are
51
+ empty no gist will be created.
52
+
53
+ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
54
+ [--skip-empty] [-P] [-f NAME|-t EXT]* FILE*
51
55
  #{executable_name} --login
52
56
  #{executable_name} [-l|-r]
53
57
 
@@ -107,6 +111,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
107
111
 
108
112
  opts.on("--no-open")
109
113
 
114
+ opts.on("--skip-empty", "Skip gisting empty files") do
115
+ options[:skip_empty] = true
116
+ end
117
+
110
118
  opts.on("-P", "--paste", "Paste from the clipboard to gist") do
111
119
  options[:paste] = true
112
120
  end
@@ -195,7 +203,8 @@ begin
195
203
  end
196
204
  end
197
205
 
198
- puts Gist.multi_gist(files, options)
206
+ output = Gist.multi_gist(files, options)
207
+ puts output if output
199
208
  end
200
209
 
201
210
  rescue Gist::Error => e
data/build/gist CHANGED
@@ -1318,7 +1318,7 @@ end
1318
1318
  module Gist
1319
1319
  extend self
1320
1320
 
1321
- VERSION = '4.6.1'
1321
+ VERSION = '4.6.2'
1322
1322
 
1323
1323
  # A list of clipboard commands with copy and paste support.
1324
1324
  CLIPBOARD_COMMANDS = {
@@ -1382,10 +1382,14 @@ module Gist
1382
1382
  #
1383
1383
  # @see http://developer.github.com/v3/gists/
1384
1384
  def gist(content, options = {})
1385
- filename = options[:filename] || "a.rb"
1385
+ filename = options[:filename] || default_filename
1386
1386
  multi_gist({filename => content}, options)
1387
1387
  end
1388
1388
 
1389
+ def default_filename
1390
+ "gistfile1.txt"
1391
+ end
1392
+
1389
1393
  # Upload a gist to https://gist.github.com
1390
1394
  #
1391
1395
  # @param [Hash] files the code you'd like to gist: filename => content
@@ -1398,6 +1402,7 @@ module Gist
1398
1402
  # @option options [String] :update the URL or id of a gist to update
1399
1403
  # @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
1400
1404
  # @option options [Boolean] :open (false) Open the resulting URL in a browser.
1405
+ # @option options [Boolean] :skip_empty (false) Skip gisting empty files.
1401
1406
  # @option options [Symbol] :output (:all) The type of return value you'd like:
1402
1407
  # :html_url gives a String containing the url to the gist in a browser
1403
1408
  # :short_url gives a String contianing a git.io url that redirects to html_url
@@ -1416,10 +1421,16 @@ module Gist
1416
1421
  json[:files] = {}
1417
1422
 
1418
1423
  files.each_pair do |(name, content)|
1419
- raise "Cannot gist empty files" if content.to_s.strip == ""
1420
- json[:files][File.basename(name)] = {:content => content}
1424
+ if content.to_s.strip == ""
1425
+ raise "Cannot gist empty files" unless options[:skip_empty]
1426
+ else
1427
+ name = name == "-" ? default_filename : File.basename(name)
1428
+ json[:files][name] = {:content => content}
1429
+ end
1421
1430
  end
1422
1431
 
1432
+ return if json[:files].empty? && options[:skip_empty]
1433
+
1423
1434
  existing_gist = options[:update].to_s.split("/").last
1424
1435
  if options[:anonymous]
1425
1436
  access_token = nil
@@ -1509,6 +1520,12 @@ module Gist
1509
1520
 
1510
1521
  def read_gist(id, file_name=nil)
1511
1522
  url = "#{base_path}/gists/#{id}"
1523
+
1524
+ access_token = auth_token()
1525
+ if access_token.to_s != ''
1526
+ url << "?access_token=" << CGI.escape(access_token)
1527
+ end
1528
+
1512
1529
  request = Net::HTTP::Get.new(url)
1513
1530
  response = http(api_url, request)
1514
1531
 
@@ -1909,7 +1926,11 @@ Instead of creating a new gist, you can update an existing one by passing its ID
1909
1926
  or URL with "-u". For this to work, you must be logged in, and have created the
1910
1927
  original gist with the same GitHub account.
1911
1928
 
1912
- Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
1929
+ If you want to skip empty files, use the --skip-empty flag. If all files are
1930
+ empty no gist will be created.
1931
+
1932
+ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
1933
+ [--skip-empty] [-P] [-f NAME|-t EXT]* FILE*
1913
1934
  #{executable_name} --login
1914
1935
  #{executable_name} [-l|-r]
1915
1936
 
@@ -1969,6 +1990,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
1969
1990
 
1970
1991
  opts.on("--no-open")
1971
1992
 
1993
+ opts.on("--skip-empty", "Skip gisting empty files") do
1994
+ options[:skip_empty] = true
1995
+ end
1996
+
1972
1997
  opts.on("-P", "--paste", "Paste from the clipboard to gist") do
1973
1998
  options[:paste] = true
1974
1999
  end
@@ -2057,7 +2082,8 @@ begin
2057
2082
  end
2058
2083
  end
2059
2084
 
2060
- puts Gist.multi_gist(files, options)
2085
+ output = Gist.multi_gist(files, options)
2086
+ puts output if output
2061
2087
  end
2062
2088
 
2063
2089
  rescue Gist::Error => e
@@ -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" "May 2017" "" "Gist manual"
4
+ .TH "GIST" "1" "January 2018" "" "Gist manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBgist\fR \- upload code to https://gist\.github\.com
@@ -149,6 +149,25 @@ gist \-a a\.rb
149
149
  .
150
150
  .IP "" 0
151
151
  .
152
+ .P
153
+ If you have a complicated authorization requirement you can manually create a token file by pasting a Github token with only the \fBgist\fR permission into a file called \fB~/\.gist\fR\. You can create one from https://github\.com/settings/tokens
154
+ .
155
+ .P
156
+ This file should contain only the token (~40 hex characters), and to make it easier to edit, can optionally have a final newline (\en or \er\en)\.
157
+ .
158
+ .P
159
+ For example, one way to create this file would be to run:
160
+ .
161
+ .IP "" 4
162
+ .
163
+ .nf
164
+
165
+ echo MY_SECRET_TOKEN > ~/\.gist
166
+ .
167
+ .fi
168
+ .
169
+ .IP "" 0
170
+ .
152
171
  .SS "GitHub Enterprise"
153
172
  If you\'d like \fBgist\fR to use your locally installed GitHub Enterprise \fIhttps://enterprise\.github\.com/\fR, you need to export the \fBGITHUB_URL\fR environment variable (usually done in your \fB~/\.bashrc\fR)\.
154
173
  .
@@ -166,7 +185,7 @@ export GITHUB_URL=http://github\.internal\.example\.com/
166
185
  Once you\'ve done this and restarted your terminal (or run \fBsource ~/\.bashrc\fR), gist will automatically use github enterprise instead of the public github\.com
167
186
  .
168
187
  .P
169
- Your token for GitHub Enterprise will be stored in \fB\.gist\.<protocol>\.<server\.name>[\.<port>]\fR (e\.g\. \fB~\.gist\.http\.github\.internal\.example\.com\fR for the GITHUB_URL example above) instead of \fB~/\.gist\fR\.
188
+ Your token for GitHub Enterprise will be stored in \fB\.gist\.<protocol>\.<server\.name>[\.<port>]\fR (e\.g\. \fB~/\.gist\.http\.github\.internal\.example\.com\fR for the GITHUB_URL example above) instead of \fB~/\.gist\fR\.
170
189
  .
171
190
  .P
172
191
  If you have multiple servers or use Enterprise and public GitHub often, you can work around this by creating scripts that set the env var and then run \fBgist\fR\. Keep in mind that to use the public GitHub you must unset the env var\. Just setting it to the public URL will not work\. Use \fBunset GITHUB_URL\fR
@@ -12,7 +12,7 @@ end
12
12
  module Gist
13
13
  extend self
14
14
 
15
- VERSION = '4.6.1'
15
+ VERSION = '4.6.2'
16
16
 
17
17
  # A list of clipboard commands with copy and paste support.
18
18
  CLIPBOARD_COMMANDS = {
@@ -76,10 +76,14 @@ module Gist
76
76
  #
77
77
  # @see http://developer.github.com/v3/gists/
78
78
  def gist(content, options = {})
79
- filename = options[:filename] || "a.rb"
79
+ filename = options[:filename] || default_filename
80
80
  multi_gist({filename => content}, options)
81
81
  end
82
82
 
83
+ def default_filename
84
+ "gistfile1.txt"
85
+ end
86
+
83
87
  # Upload a gist to https://gist.github.com
84
88
  #
85
89
  # @param [Hash] files the code you'd like to gist: filename => content
@@ -92,6 +96,7 @@ module Gist
92
96
  # @option options [String] :update the URL or id of a gist to update
93
97
  # @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
94
98
  # @option options [Boolean] :open (false) Open the resulting URL in a browser.
99
+ # @option options [Boolean] :skip_empty (false) Skip gisting empty files.
95
100
  # @option options [Symbol] :output (:all) The type of return value you'd like:
96
101
  # :html_url gives a String containing the url to the gist in a browser
97
102
  # :short_url gives a String contianing a git.io url that redirects to html_url
@@ -110,10 +115,16 @@ module Gist
110
115
  json[:files] = {}
111
116
 
112
117
  files.each_pair do |(name, content)|
113
- raise "Cannot gist empty files" if content.to_s.strip == ""
114
- json[:files][File.basename(name)] = {:content => content}
118
+ if content.to_s.strip == ""
119
+ raise "Cannot gist empty files" unless options[:skip_empty]
120
+ else
121
+ name = name == "-" ? default_filename : File.basename(name)
122
+ json[:files][name] = {:content => content}
123
+ end
115
124
  end
116
125
 
126
+ return if json[:files].empty? && options[:skip_empty]
127
+
117
128
  existing_gist = options[:update].to_s.split("/").last
118
129
  if options[:anonymous]
119
130
  access_token = nil
@@ -203,6 +214,12 @@ module Gist
203
214
 
204
215
  def read_gist(id, file_name=nil)
205
216
  url = "#{base_path}/gists/#{id}"
217
+
218
+ access_token = auth_token()
219
+ if access_token.to_s != ''
220
+ url << "?access_token=" << CGI.escape(access_token)
221
+ end
222
+
206
223
  request = Net::HTTP::Get.new(url)
207
224
  response = http(api_url, request)
208
225
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gist
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.1
4
+ version: 4.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conrad Irwin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-17 00:00:00.000000000 Z
12
+ date: 2018-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake