jist 1.1.1.pre.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -1
- data/bin/jist +9 -2
- data/jist.gemspec +1 -2
- data/lib/jist.rb +47 -3
- data/spec/clipboard_spec.rb +2 -2
- data/spec/shorten_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +11 -10
data/Gemfile
CHANGED
data/bin/jist
CHANGED
@@ -29,6 +29,9 @@ Anonymous gists are not associated with your GitHub account, they can be created
|
|
29
29
|
with "-a" even after you have used "jist --login". If you already have an access
|
30
30
|
token with the "gist" scope, you can pass that with "-t".
|
31
31
|
|
32
|
+
If you would like to shorten the resulting gist URL, use the -s flag. This will
|
33
|
+
use GitHub's URL shortener, git.io.
|
34
|
+
|
32
35
|
To copy the resulting URL to your clipboard you can use the -c option, or to just
|
33
36
|
open it directly in your browser, use -o. You can add `alias jist='jist -c'` to
|
34
37
|
your shell's rc file to configure this behaviour by default.
|
@@ -37,7 +40,7 @@ Instead of creating a new jist, you can update an existing one by passing its ID
|
|
37
40
|
or URL with "-u". For this to work, you must be logged in, and have created the
|
38
41
|
original gist with the same GitHub account.
|
39
42
|
|
40
|
-
Usage: #{executable_name} [-o|-c] [-p] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f NAME]* FILE*
|
43
|
+
Usage: #{executable_name} [-o|-c] [-p] [-s] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f NAME]* FILE*
|
41
44
|
#{executable_name} --login
|
42
45
|
|
43
46
|
EOS
|
@@ -60,6 +63,10 @@ Usage: #{executable_name} [-o|-c] [-p] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f
|
|
60
63
|
options[:description] = description
|
61
64
|
end
|
62
65
|
|
66
|
+
opts.on("-s", "--shorten", "Shorten the gist URL using git.io.") do |shorten|
|
67
|
+
options[:shorten] = shorten
|
68
|
+
end
|
69
|
+
|
63
70
|
opts.on("-u", "--update [ URL | ID ]", "Update an existing gist.") do |update|
|
64
71
|
options[:update] = update
|
65
72
|
end
|
@@ -99,7 +106,7 @@ opts.parse!
|
|
99
106
|
|
100
107
|
begin
|
101
108
|
if options[:paste]
|
102
|
-
puts Jist.gist(
|
109
|
+
puts Jist.gist(Jist.paste, options)['html_url']
|
103
110
|
elsif ARGV.size == 0
|
104
111
|
$stderr.puts "(type a gist. <ctrl-c> to cancel, <ctrl-d> when done)" if $stdin.tty?
|
105
112
|
puts Jist.gist(ARGF.read, options)['html_url']
|
data/jist.gemspec
CHANGED
data/lib/jist.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
require 'net/https'
|
2
2
|
require 'cgi'
|
3
3
|
require 'json'
|
4
|
-
require 'clippy'
|
5
4
|
|
6
5
|
# It just gists.
|
7
6
|
module Jist
|
8
7
|
extend self
|
9
8
|
|
10
|
-
VERSION = '1.
|
9
|
+
VERSION = '1.2.0'
|
10
|
+
|
11
|
+
# A list of clipboard commands with copy and paste support.
|
12
|
+
CLIPBOARD_COMMANDS = {
|
13
|
+
'xclip' => 'xclip -o',
|
14
|
+
'xsel' => 'xsel -o',
|
15
|
+
'pbcopy' => 'pbpaste',
|
16
|
+
'putclip' => 'getclip'
|
17
|
+
}
|
11
18
|
|
12
19
|
# Exception tag for errors raised while gisting.
|
13
20
|
module Error; end
|
@@ -21,6 +28,7 @@ module Jist
|
|
21
28
|
# @option options [String] :filename ('a.rb') the filename
|
22
29
|
# @option options [Boolean] :public (false) is this gist public
|
23
30
|
# @option options [Boolean] :anonymous (false) is this gist anonymous
|
31
|
+
# @option options [Boolean] :shorten (false) Shorten the resulting URL using git.io.
|
24
32
|
# @option options [String] :access_token (`File.read("~/.jist")`) The OAuth2 access token.
|
25
33
|
# @option options [String] :update the URL or id of a gist to update
|
26
34
|
# @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
|
@@ -43,6 +51,7 @@ module Jist
|
|
43
51
|
# @option options [String] :description the description
|
44
52
|
# @option options [Boolean] :public (false) is this gist public
|
45
53
|
# @option options [Boolean] :anonymous (false) is this gist anonymous
|
54
|
+
# @option options [Boolean] :shorten (false) Shorten the resulting URL using git.io.
|
46
55
|
# @option options [String] :access_token (`File.read("~/.jist")`) The OAuth2 access token.
|
47
56
|
# @option options [String] :update the URL or id of a gist to update
|
48
57
|
# @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
|
@@ -98,6 +107,20 @@ module Jist
|
|
98
107
|
raise e.extend Error
|
99
108
|
end
|
100
109
|
|
110
|
+
# Convert long github urls into shotr git.io ones
|
111
|
+
#
|
112
|
+
# @param [String] url
|
113
|
+
# @return [String] shortened url, or long url if shortening fails
|
114
|
+
def shorten(url)
|
115
|
+
response = Net::HTTP.post_form(URI("http://git.io/"), :url => url)
|
116
|
+
case response.code
|
117
|
+
when "201"
|
118
|
+
response['Location']
|
119
|
+
else
|
120
|
+
url
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
101
124
|
# Log the user into jist.
|
102
125
|
#
|
103
126
|
# This method asks the user for a username and password, and tries to obtain
|
@@ -181,12 +204,33 @@ module Jist
|
|
181
204
|
def on_success(body, options={})
|
182
205
|
json = JSON.parse(body)
|
183
206
|
|
184
|
-
|
207
|
+
json['html_url'] = shorten(json['html_url']) if options[:shorten]
|
208
|
+
Jist.copy(json['html_url']) if options[:copy]
|
185
209
|
Jist.open(json['html_url']) if options[:open]
|
186
210
|
|
187
211
|
json
|
188
212
|
end
|
189
213
|
|
214
|
+
# Copy a string to the clipboard.
|
215
|
+
#
|
216
|
+
# @param [String] content
|
217
|
+
# @raise [RuntimeError] if no clipboard integration could be found
|
218
|
+
#
|
219
|
+
# This method was heavily inspired by defunkt's Gist#copy,
|
220
|
+
# @see https://github.com/defunkt/gist/blob/bca9b29/lib/gist.rb#L178
|
221
|
+
def copy(content)
|
222
|
+
IO.popen(clipboard_command(:copy), 'r+') { |clip| clip.print content }
|
223
|
+
raise "Copying to clipboard failed" unless paste == content
|
224
|
+
end
|
225
|
+
|
226
|
+
# Get a string from the clipboard.
|
227
|
+
#
|
228
|
+
# @param [String] content
|
229
|
+
# @raise [RuntimeError] if no clipboard integration could be found
|
230
|
+
def paste
|
231
|
+
`#{clipboard_command(:paste)}`
|
232
|
+
end
|
233
|
+
|
190
234
|
# Find command from PATH environment.
|
191
235
|
#
|
192
236
|
# @param [String] cmd command name to find
|
data/spec/clipboard_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe '...' do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should try to copy the url when the clipboard option is passed' do
|
19
|
-
|
19
|
+
Jist.should_receive(:copy).with(@bobo_url)
|
20
20
|
ask_for_copy
|
21
21
|
end
|
22
22
|
|
@@ -29,6 +29,6 @@ describe '...' do
|
|
29
29
|
ENV['PATH'] = ''
|
30
30
|
lambda{
|
31
31
|
ask_for_copy
|
32
|
-
}.should raise_error(/
|
32
|
+
}.should raise_error(/Could not find copy command/)
|
33
33
|
end
|
34
34
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
describe '...' do
|
2
|
+
before do
|
3
|
+
stub_request(:post, /api\.github.com\/gists\?access_token=.*/).to_return(:body => '{"html_url": "http://github.com/"}')
|
4
|
+
stub_request(:post, "http://git.io/").to_return(:status => 201, :headers => { 'Location' => 'http://git.io/XXXXXX' })
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should return a shortened version of the URL" do
|
8
|
+
Jist.gist("Test gist", :shorten => true).should == {"html_url" => "http://git.io/XXXXXX"}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Conrad Irwin
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: json
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: rake
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
|
-
type: :
|
38
|
+
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: rspec
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: webmock
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/jist.rb
|
94
94
|
- spec/clipboard_spec.rb
|
95
95
|
- spec/proxy_spec.rb
|
96
|
+
- spec/shorten_spec.rb
|
96
97
|
- spec/spec_helper.rb
|
97
98
|
homepage: https://github.com/ConradIrwin/jist
|
98
99
|
licenses:
|
@@ -110,9 +111,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
112
|
none: false
|
112
113
|
requirements:
|
113
|
-
- - ! '
|
114
|
+
- - ! '>='
|
114
115
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
116
|
+
version: '0'
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
119
|
rubygems_version: 1.8.24
|