Skip to content

Commit

Permalink
v4.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed Jan 9, 2018
1 parent 83c91b2 commit 249fb99
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
38 changes: 32 additions & 6 deletions build/gist
Expand Up @@ -1318,7 +1318,7 @@ end
module Gist
extend self

VERSION = '4.6.1'
VERSION = '4.6.2'

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

def default_filename
"gistfile1.txt"
end

# Upload a gist to https://gist.github.com
#
# @param [Hash] files the code you'd like to gist: filename => content
Expand All @@ -1398,6 +1402,7 @@ module Gist
# @option options [String] :update the URL or id of a gist to update
# @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
# @option options [Boolean] :open (false) Open the resulting URL in a browser.
# @option options [Boolean] :skip_empty (false) Skip gisting empty files.
# @option options [Symbol] :output (:all) The type of return value you'd like:
# :html_url gives a String containing the url to the gist in a browser
# :short_url gives a String contianing a git.io url that redirects to html_url
Expand All @@ -1416,10 +1421,16 @@ module Gist
json[:files] = {}

files.each_pair do |(name, content)|
raise "Cannot gist empty files" if content.to_s.strip == ""
json[:files][File.basename(name)] = {:content => content}
if content.to_s.strip == ""
raise "Cannot gist empty files" unless options[:skip_empty]
else
name = name == "-" ? default_filename : File.basename(name)
json[:files][name] = {:content => content}
end
end

return if json[:files].empty? && options[:skip_empty]

existing_gist = options[:update].to_s.split("/").last
if options[:anonymous]
access_token = nil
Expand Down Expand Up @@ -1509,6 +1520,12 @@ module Gist

def read_gist(id, file_name=nil)
url = "#{base_path}/gists/#{id}"

access_token = auth_token()
if access_token.to_s != ''
url << "?access_token=" << CGI.escape(access_token)
end

request = Net::HTTP::Get.new(url)
response = http(api_url, request)

Expand Down Expand Up @@ -1909,7 +1926,11 @@ Instead of creating a new gist, you can update an existing one by passing its ID
or URL with "-u". For this to work, you must be logged in, and have created the
original gist with the same GitHub account.
Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
If you want to skip empty files, use the --skip-empty flag. If all files are
empty no gist will be created.
Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
[--skip-empty] [-P] [-f NAME|-t EXT]* FILE*
#{executable_name} --login
#{executable_name} [-l|-r]
Expand Down Expand Up @@ -1969,6 +1990,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]

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

opts.on("--skip-empty", "Skip gisting empty files") do
options[:skip_empty] = true
end

opts.on("-P", "--paste", "Paste from the clipboard to gist") do
options[:paste] = true
end
Expand Down Expand Up @@ -2057,7 +2082,8 @@ begin
end
end

puts Gist.multi_gist(files, options)
output = Gist.multi_gist(files, options)
puts output if output
end

rescue Gist::Error => e
Expand Down
23 changes: 21 additions & 2 deletions build/gist.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIST" "1" "May 2017" "" "Gist manual"
.TH "GIST" "1" "January 2018" "" "Gist manual"
.
.SH "NAME"
\fBgist\fR \- upload code to https://gist\.github\.com
Expand Down Expand Up @@ -149,6 +149,25 @@ gist \-a a\.rb
.
.IP "" 0
.
.P
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
.
.P
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)\.
.
.P
For example, one way to create this file would be to run:
.
.IP "" 4
.
.nf

echo MY_SECRET_TOKEN > ~/\.gist
.
.fi
.
.IP "" 0
.
.SS "GitHub Enterprise"
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)\.
.
Expand All @@ -166,7 +185,7 @@ export GITHUB_URL=http://github\.internal\.example\.com/
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
.
.P
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\.
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\.
.
.P
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
Expand Down
2 changes: 1 addition & 1 deletion lib/gist.rb
Expand Up @@ -12,7 +12,7 @@
module Gist
extend self

VERSION = '4.6.1'
VERSION = '4.6.2'

# A list of clipboard commands with copy and paste support.
CLIPBOARD_COMMANDS = {
Expand Down

0 comments on commit 249fb99

Please sign in to comment.