From 5b19eed2794b745f57b941e244e946591b36c790 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 18 Nov 2015 19:03:59 -0800 Subject: [PATCH] v4.5.0 --- build/gist | 40 ++++++++++++++++++++++++++++++++++++++-- build/gist.1 | 18 +----------------- lib/gist.rb | 2 +- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/build/gist b/build/gist index c4e8c4d..e94af4e 100755 --- a/build/gist +++ b/build/gist @@ -1318,7 +1318,7 @@ end module Gist extend self - VERSION = '4.4.2' + VERSION = '4.5.0' # A list of clipboard commands with copy and paste support. CLIPBOARD_COMMANDS = { @@ -1507,6 +1507,28 @@ module Gist end + def read_gist(id, file_name=nil) + url = "#{base_path}/gists/#{id}" + request = Net::HTTP::Get.new(url) + response = http(api_url, request) + + if response.code == '200' + body = JSON.parse(response.body) + files = body["files"] + + if file_name + file = files[file_name] + raise Error, "Gist with id of #{id} and file #{file_name} does not exist." unless file + else + file = files.values.first + end + + puts file["content"] + else + raise Error, "Gist with id of #{id} does not exist." + end + end + def get_gist_pages(url) request = Net::HTTP::Get.new(url) @@ -1820,7 +1842,10 @@ end # Silence Ctrl-C's trap('INT'){ exit 1 } -trap('PIPE', 'EXIT') + +if Signal.list.include? 'PIPE' + trap('PIPE', 'EXIT') +end require 'optparse' @@ -1863,6 +1888,7 @@ 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* #{executable_name} --login + #{executable_name} [-l|-r] EOS @@ -1932,6 +1958,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] options[:list] = user end + opts.on("-r", "--read ID [FILENAME]", "Read a gist and print out the contents") do |id| + options[:read] = id + end + opts.on_tail("-h","--help", "Show this message.") do puts opts exit @@ -1970,6 +2000,12 @@ begin exit end + if options.key? :read + file_name = ARGV.first + Gist.read_gist(options[:read], file_name) + exit + end + if options[:paste] puts Gist.gist(Gist.paste, options) else diff --git a/build/gist.1 b/build/gist.1 index 03b5771..d8b5f53 100644 --- a/build/gist.1 +++ b/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" "July 2015" "" "Gist manual" +.TH "GIST" "1" "November 2015" "" "Gist manual" . .SH "NAME" \fBgist\fR \- upload code to https://gist\.github\.com @@ -123,22 +123,6 @@ Success! https://github\.com/settings/applications .IP "" 0 . .P -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\. -. -.P -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\. -. -.IP "" 4 -. -.nf - -gem update gist -. -.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\. . .IP "\(bu" 4 diff --git a/lib/gist.rb b/lib/gist.rb index 0ec8271..16ccfed 100644 --- a/lib/gist.rb +++ b/lib/gist.rb @@ -12,7 +12,7 @@ module Gist extend self - VERSION = '4.4.2' + VERSION = '4.5.0' # A list of clipboard commands with copy and paste support. CLIPBOARD_COMMANDS = {