Skip to content

Commit 0e1b19d

Browse files
committed
v4.6.0
1 parent 55fb758 commit 0e1b19d

File tree

3 files changed

+76
-18
lines changed

3 files changed

+76
-18
lines changed

build/gist

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ end
16091609
module Gist
16101610
extend self
16111611

1612-
VERSION = '4.5.0'
1612+
VERSION = '4.6.0'
16131613

16141614
# A list of clipboard commands with copy and paste support.
16151615
CLIPBOARD_COMMANDS = {
@@ -1820,6 +1820,27 @@ module Gist
18201820
end
18211821
end
18221822

1823+
def delete_gist(id)
1824+
id = id.split("/").last
1825+
url = "#{base_path}/gists/#{id}"
1826+
1827+
access_token = auth_token()
1828+
if access_token.to_s != ''
1829+
url << "?access_token=" << CGI.escape(access_token)
1830+
1831+
request = Net::HTTP::Delete.new(url)
1832+
response = http(api_url, request)
1833+
else
1834+
raise Error, "Not authenticated. Use 'gist --login' to login."
1835+
end
1836+
1837+
if response.code == '204'
1838+
puts "Deleted!"
1839+
else
1840+
raise Error, "Gist with id of #{id} does not exist."
1841+
end
1842+
end
1843+
18231844
def get_gist_pages(url)
18241845

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

2279+
opts.on("--delete [ URL | ID ]", "Delete a gist") do |id|
2280+
options[:delete] = id
2281+
end
2282+
22582283
opts.on_tail("-h","--help", "Show this message.") do
22592284
puts opts
22602285
exit
@@ -2299,6 +2324,11 @@ begin
22992324
exit
23002325
end
23012326

2327+
if options.key? :delete
2328+
Gist.delete_gist(options[:delete])
2329+
exit
2330+
end
2331+
23022332
if options[:paste]
23032333
puts Gist.gist(Gist.paste, options)
23042334
else

build/gist.1

Lines changed: 44 additions & 16 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" "November 2015" "" "Gist manual"
4+
.TH "GIST" "1" "May 2017" "" "Gist manual"
55
.
66
.SH "NAME"
77
\fBgist\fR \- upload code to https://gist\.github\.com
@@ -99,6 +99,22 @@ To list (public gists or all gists for authed user) gists for user
9999
.IP
100100
gist \-l : all gists for authed user gist \-l defunkt : list defunkt\'s public gists
101101
.
102+
.IP "" 0
103+
.
104+
.P
105+
To read a gist and print it to STDOUT
106+
.
107+
.IP "" 4
108+
.
109+
.nf
110+
111+
gist \-r GIST_ID
112+
gist \-r 374130
113+
.
114+
.fi
115+
.
116+
.IP "" 0
117+
.
102118
.IP "\(bu" 4
103119
See \fBgist \-\-help\fR for more detail\.
104120
.
@@ -116,14 +132,14 @@ Obtaining OAuth2 access_token from github\.
116132
GitHub username: ConradIrwin
117133
GitHub password:
118134
2\-factor auth code:
119-
Success! https://github\.com/settings/applications
135+
Success! https://github\.com/settings/tokens
120136
.
121137
.fi
122138
.
123139
.IP "" 0
124140
.
125141
.P
126-
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\.
142+
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\.
127143
.
128144
.IP "\(bu" 4
129145
After you\'ve done this, you can still upload gists anonymously with \fB\-a\fR\.
@@ -133,6 +149,31 @@ gist \-a a\.rb
133149
.
134150
.IP "" 0
135151
.
152+
.SS "GitHub Enterprise"
153+
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+
.
155+
.IP "" 4
156+
.
157+
.nf
158+
159+
export GITHUB_URL=http://github\.internal\.example\.com/
160+
.
161+
.fi
162+
.
163+
.IP "" 0
164+
.
165+
.P
166+
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+
.
168+
.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\.
170+
.
171+
.P
172+
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
173+
.
174+
.SS "Token file format"
175+
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
176+
.
136177
.TP
137178
You can also use Gist as a library from inside your ruby code:
138179
.
@@ -188,19 +229,6 @@ This will take them through the process of obtaining an OAuth2 token, and storin
188229
.
189230
.IP "" 0
190231
.
191-
.SH "GitHub enterprise"
192-
.
193-
.IP "\(bu" 4
194-
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\.
195-
.
196-
.IP
197-
export GITHUB_URL=http://github\.internal\.example\.com/
198-
.
199-
.IP "\(bu" 4
200-
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
201-
.
202-
.IP "" 0
203-
.
204232
.SH "Configuration"
205233
.
206234
.IP "\(bu" 4

lib/gist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
module Gist
1919
extend self
2020

21-
VERSION = '4.5.0'
21+
VERSION = '4.6.0'
2222

2323
# A list of clipboard commands with copy and paste support.
2424
CLIPBOARD_COMMANDS = {

0 commit comments

Comments
 (0)