Skip to content

Commit

Permalink
v4.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed May 16, 2017
1 parent 55fb758 commit 0e1b19d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 18 deletions.
32 changes: 31 additions & 1 deletion build/gist
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ end
module Gist
extend self

VERSION = '4.5.0'
VERSION = '4.6.0'

# A list of clipboard commands with copy and paste support.
CLIPBOARD_COMMANDS = {
Expand Down Expand Up @@ -1820,6 +1820,27 @@ module Gist
end
end

def delete_gist(id)
id = id.split("/").last
url = "#{base_path}/gists/#{id}"

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

request = Net::HTTP::Delete.new(url)
response = http(api_url, request)
else
raise Error, "Not authenticated. Use 'gist --login' to login."
end

if response.code == '204'
puts "Deleted!"
else
raise Error, "Gist with id of #{id} does not exist."
end
end

def get_gist_pages(url)

request = Net::HTTP::Get.new(url)
Expand Down Expand Up @@ -2255,6 +2276,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
options[:read] = id
end

opts.on("--delete [ URL | ID ]", "Delete a gist") do |id|
options[:delete] = id
end

opts.on_tail("-h","--help", "Show this message.") do
puts opts
exit
Expand Down Expand Up @@ -2299,6 +2324,11 @@ begin
exit
end

if options.key? :delete
Gist.delete_gist(options[:delete])
exit
end

if options[:paste]
puts Gist.gist(Gist.paste, options)
else
Expand Down
60 changes: 44 additions & 16 deletions build/gist.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIST" "1" "November 2015" "" "Gist manual"
.TH "GIST" "1" "May 2017" "" "Gist manual"
.
.SH "NAME"
\fBgist\fR \- upload code to https://gist\.github\.com
Expand Down Expand Up @@ -99,6 +99,22 @@ To list (public gists or all gists for authed user) gists for user
.IP
gist \-l : all gists for authed user gist \-l defunkt : list defunkt\'s public gists
.
.IP "" 0
.
.P
To read a gist and print it to STDOUT
.
.IP "" 4
.
.nf

gist \-r GIST_ID
gist \-r 374130
.
.fi
.
.IP "" 0
.
.IP "\(bu" 4
See \fBgist \-\-help\fR for more detail\.
.
Expand All @@ -116,14 +132,14 @@ Obtaining OAuth2 access_token from github\.
GitHub username: ConradIrwin
GitHub password:
2\-factor auth code:
Success! https://github\.com/settings/applications
Success! https://github\.com/settings/tokens
.
.fi
.
.IP "" 0
.
.P
This token is stored in \fB~/\.gist\fR and used for all future gisting\. If you need to you can revoke it from https://github\.com/settings/applications, or just delete the file\. If you need to store tokens for both github\.com and a Github Enterprise instance you can save your Github Enterprise token in \fB~/\.gist\.github\.example\.com\fR where "github\.example\.com" is the URL for your Github Enterprise instance\.
This token is stored in \fB~/\.gist\fR and used for all future gisting\. If you need to you can revoke it from https://github\.com/settings/tokens, or just delete the file\.
.
.IP "\(bu" 4
After you\'ve done this, you can still upload gists anonymously with \fB\-a\fR\.
Expand All @@ -133,6 +149,31 @@ gist \-a a\.rb
.
.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)\.
.
.IP "" 4
.
.nf

export GITHUB_URL=http://github\.internal\.example\.com/
.
.fi
.
.IP "" 0
.
.P
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\.
.
.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
.
.SS "Token file format"
If you cannot use passwords, as most Enterprise installations do, you can generate the token via the web interface and then simply save the string in the correct file\. Avoid line breaks or you might see: \fB$ gist \-l Error: Bad credentials\fR
.
.TP
You can also use Gist as a library from inside your ruby code:
.
Expand Down Expand Up @@ -188,19 +229,6 @@ This will take them through the process of obtaining an OAuth2 token, and storin
.
.IP "" 0
.
.SH "GitHub enterprise"
.
.IP "\(bu" 4
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 in your \fB~/\.bashrc\fR\.
.
.IP
export GITHUB_URL=http://github\.internal\.example\.com/
.
.IP "\(bu" 4
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
.
.IP "" 0
.
.SH "Configuration"
.
.IP "\(bu" 4
Expand Down
2 changes: 1 addition & 1 deletion lib/gist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module Gist
extend self

VERSION = '4.5.0'
VERSION = '4.6.0'

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

0 comments on commit 0e1b19d

Please sign in to comment.