Skip to content

Commit 5b19eed

Browse files
committed
v4.5.0
1 parent 59c0b8f commit 5b19eed

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

build/gist

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

1321-
VERSION = '4.4.2'
1321+
VERSION = '4.5.0'
13221322

13231323
# A list of clipboard commands with copy and paste support.
13241324
CLIPBOARD_COMMANDS = {
@@ -1507,6 +1507,28 @@ module Gist
15071507

15081508
end
15091509

1510+
def read_gist(id, file_name=nil)
1511+
url = "#{base_path}/gists/#{id}"
1512+
request = Net::HTTP::Get.new(url)
1513+
response = http(api_url, request)
1514+
1515+
if response.code == '200'
1516+
body = JSON.parse(response.body)
1517+
files = body["files"]
1518+
1519+
if file_name
1520+
file = files[file_name]
1521+
raise Error, "Gist with id of #{id} and file #{file_name} does not exist." unless file
1522+
else
1523+
file = files.values.first
1524+
end
1525+
1526+
puts file["content"]
1527+
else
1528+
raise Error, "Gist with id of #{id} does not exist."
1529+
end
1530+
end
1531+
15101532
def get_gist_pages(url)
15111533

15121534
request = Net::HTTP::Get.new(url)
@@ -1820,7 +1842,10 @@ end
18201842

18211843
# Silence Ctrl-C's
18221844
trap('INT'){ exit 1 }
1823-
trap('PIPE', 'EXIT')
1845+
1846+
if Signal.list.include? 'PIPE'
1847+
trap('PIPE', 'EXIT')
1848+
end
18241849

18251850
require 'optparse'
18261851

@@ -1863,6 +1888,7 @@ original gist with the same GitHub account.
18631888
18641889
Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
18651890
#{executable_name} --login
1891+
#{executable_name} [-l|-r]
18661892
18671893
EOS
18681894

@@ -1932,6 +1958,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
19321958
options[:list] = user
19331959
end
19341960

1961+
opts.on("-r", "--read ID [FILENAME]", "Read a gist and print out the contents") do |id|
1962+
options[:read] = id
1963+
end
1964+
19351965
opts.on_tail("-h","--help", "Show this message.") do
19361966
puts opts
19371967
exit
@@ -1970,6 +2000,12 @@ begin
19702000
exit
19712001
end
19722002

2003+
if options.key? :read
2004+
file_name = ARGV.first
2005+
Gist.read_gist(options[:read], file_name)
2006+
exit
2007+
end
2008+
19732009
if options[:paste]
19742010
puts Gist.gist(Gist.paste, options)
19752011
else

build/gist.1

Lines changed: 1 addition & 17 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" "July 2015" "" "Gist manual"
4+
.TH "GIST" "1" "November 2015" "" "Gist manual"
55
.
66
.SH "NAME"
77
\fBgist\fR \- upload code to https://gist\.github\.com
@@ -123,22 +123,6 @@ Success! https://github\.com/settings/applications
123123
.IP "" 0
124124
.
125125
.P
126-
You can read the 2\-factor auth code from an sms or the authentication app, depending on how you set your account up \fIhttps://github\.com/settings/admin\fR\.
127-
.
128-
.P
129-
Note: 2\-factor authentication just appeared recently \fIhttps://github\.com/blog/1614\-two\-factor\-authentication\fR, so if you run into errors, update the gist gem\.
130-
.
131-
.IP "" 4
132-
.
133-
.nf
134-
135-
gem update gist
136-
.
137-
.fi
138-
.
139-
.IP "" 0
140-
.
141-
.P
142126
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\.
143127
.
144128
.IP "\(bu" 4

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.4.2'
15+
VERSION = '4.5.0'
1616

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

0 commit comments

Comments
 (0)