Skip to content

Commit 249fb99

Browse files
committed
v4.6.2
1 parent 83c91b2 commit 249fb99

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

build/gist

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ end
13181318
module Gist
13191319
extend self
13201320

1321-
VERSION = '4.6.1'
1321+
VERSION = '4.6.2'
13221322

13231323
# A list of clipboard commands with copy and paste support.
13241324
CLIPBOARD_COMMANDS = {
@@ -1382,10 +1382,14 @@ module Gist
13821382
#
13831383
# @see http://developer.github.com/v3/gists/
13841384
def gist(content, options = {})
1385-
filename = options[:filename] || "a.rb"
1385+
filename = options[:filename] || default_filename
13861386
multi_gist({filename => content}, options)
13871387
end
13881388

1389+
def default_filename
1390+
"gistfile1.txt"
1391+
end
1392+
13891393
# Upload a gist to https://gist.github.com
13901394
#
13911395
# @param [Hash] files the code you'd like to gist: filename => content
@@ -1398,6 +1402,7 @@ module Gist
13981402
# @option options [String] :update the URL or id of a gist to update
13991403
# @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
14001404
# @option options [Boolean] :open (false) Open the resulting URL in a browser.
1405+
# @option options [Boolean] :skip_empty (false) Skip gisting empty files.
14011406
# @option options [Symbol] :output (:all) The type of return value you'd like:
14021407
# :html_url gives a String containing the url to the gist in a browser
14031408
# :short_url gives a String contianing a git.io url that redirects to html_url
@@ -1416,10 +1421,16 @@ module Gist
14161421
json[:files] = {}
14171422

14181423
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
14211430
end
14221431

1432+
return if json[:files].empty? && options[:skip_empty]
1433+
14231434
existing_gist = options[:update].to_s.split("/").last
14241435
if options[:anonymous]
14251436
access_token = nil
@@ -1509,6 +1520,12 @@ module Gist
15091520

15101521
def read_gist(id, file_name=nil)
15111522
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+
15121529
request = Net::HTTP::Get.new(url)
15131530
response = http(api_url, request)
15141531

@@ -1909,7 +1926,11 @@ Instead of creating a new gist, you can update an existing one by passing its ID
19091926
or URL with "-u". For this to work, you must be logged in, and have created the
19101927
original gist with the same GitHub account.
19111928
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*
19131934
#{executable_name} --login
19141935
#{executable_name} [-l|-r]
19151936
@@ -1969,6 +1990,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
19691990

19701991
opts.on("--no-open")
19711992

1993+
opts.on("--skip-empty", "Skip gisting empty files") do
1994+
options[:skip_empty] = true
1995+
end
1996+
19721997
opts.on("-P", "--paste", "Paste from the clipboard to gist") do
19731998
options[:paste] = true
19741999
end
@@ -2057,7 +2082,8 @@ begin
20572082
end
20582083
end
20592084

2060-
puts Gist.multi_gist(files, options)
2085+
output = Gist.multi_gist(files, options)
2086+
puts output if output
20612087
end
20622088

20632089
rescue Gist::Error => e

build/gist.1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "GIST" "1" "May 2017" "" "Gist manual"
4+
.TH "GIST" "1" "January 2018" "" "Gist manual"
55
.
66
.SH "NAME"
77
\fBgist\fR \- upload code to https://gist\.github\.com
@@ -149,6 +149,25 @@ gist \-a a\.rb
149149
.
150150
.IP "" 0
151151
.
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+
.
152171
.SS "GitHub Enterprise"
153172
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)\.
154173
.
@@ -166,7 +185,7 @@ export GITHUB_URL=http://github\.internal\.example\.com/
166185
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
167186
.
168187
.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\.
170189
.
171190
.P
172191
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

lib/gist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
module Gist
1313
extend self
1414

15-
VERSION = '4.6.1'
15+
VERSION = '4.6.2'
1616

1717
# A list of clipboard commands with copy and paste support.
1818
CLIPBOARD_COMMANDS = {

0 commit comments

Comments
 (0)