gist 1.0.3 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +24 -1
- data/lib/gist.rb +65 -13
- data/lib/gist/version.rb +1 -1
- data/man/gist.1 +10 -14
- data/man/gist.1.html +8 -18
- metadata +2 -2
data/README.markdown
CHANGED
@@ -16,6 +16,7 @@ Old school:
|
|
16
16
|
chmod 755 gist &&
|
17
17
|
mv gist /usr/local/bin/gist
|
18
18
|
|
19
|
+
|
19
20
|
Use
|
20
21
|
---
|
21
22
|
|
@@ -24,6 +25,7 @@ Use
|
|
24
25
|
echo "puts :hi" | gist -t rb
|
25
26
|
gist script.py
|
26
27
|
|
28
|
+
|
27
29
|
Authentication
|
28
30
|
--------------
|
29
31
|
|
@@ -34,6 +36,26 @@ Just have your git config set up with your GitHub username and token.
|
|
34
36
|
|
35
37
|
You can find your token under [your account](https://github.com/account).
|
36
38
|
|
39
|
+
You can also define github.token to be a command which returns the
|
40
|
+
actual token on stdout by setting the variable to a command string
|
41
|
+
prefixed with `!`. For example, the following command fetches the
|
42
|
+
token from a password item named "github.token" on the Mac OS
|
43
|
+
Keychain:
|
44
|
+
|
45
|
+
token = !security 2>&1 >/dev/null find-generic-password -gs github.token | ruby -e 'print $1 if STDIN.gets =~ /^password: \\\"(.*)\\\"$/'
|
46
|
+
|
47
|
+
|
48
|
+
Defaults
|
49
|
+
--------
|
50
|
+
|
51
|
+
You can set a few options in your git config (using git-config(1)) to
|
52
|
+
control the default behavior of gist(1).
|
53
|
+
|
54
|
+
* gist.private - boolean (yes or no) - Determines whether to make a gist
|
55
|
+
private by default
|
56
|
+
|
57
|
+
* gist.extension - string - Default extension for gists you create.
|
58
|
+
|
37
59
|
|
38
60
|
Proxies
|
39
61
|
-------
|
@@ -42,14 +64,15 @@ Set the HTTP_PROXY env variable to use a proxy.
|
|
42
64
|
|
43
65
|
$ HTTP_PROXY=host:port gist file.rb
|
44
66
|
|
67
|
+
|
45
68
|
Manual
|
46
69
|
------
|
47
70
|
|
48
|
-
|
49
71
|
Visit <http://defunkt.github.com/gist/> or use:
|
50
72
|
|
51
73
|
$ gist -m
|
52
74
|
|
75
|
+
|
53
76
|
Ninja vs Shark
|
54
77
|
--------------
|
55
78
|
|
data/lib/gist.rb
CHANGED
@@ -32,14 +32,15 @@ module Gist
|
|
32
32
|
|
33
33
|
# Parses command line arguments and does what needs to be done.
|
34
34
|
def execute(*args)
|
35
|
-
private_gist =
|
36
|
-
|
35
|
+
private_gist = defaults["private"]
|
36
|
+
gist_filename = nil
|
37
|
+
gist_extension = defaults["extension"]
|
37
38
|
|
38
39
|
opts = OptionParser.new do |opts|
|
39
40
|
opts.banner = "Usage: gist [options] [filename or stdin]"
|
40
41
|
|
41
|
-
opts.on('-p', '--private', 'Make the gist private') do
|
42
|
-
private_gist =
|
42
|
+
opts.on('-p', '--[no-]private', 'Make the gist private') do |priv|
|
43
|
+
private_gist = priv
|
43
44
|
end
|
44
45
|
|
45
46
|
t_desc = 'Set syntax highlighting of the Gist by file extension'
|
@@ -51,6 +52,11 @@ module Gist
|
|
51
52
|
Gist::Manpage.display("gist")
|
52
53
|
end
|
53
54
|
|
55
|
+
opts.on('-v', '--version', 'Print version') do
|
56
|
+
puts Gist::Version
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
54
60
|
opts.on('-h', '--help', 'Display this screen') do
|
55
61
|
puts opts
|
56
62
|
exit
|
@@ -72,6 +78,7 @@ module Gist
|
|
72
78
|
# Check if arg is a file. If so, grab the content.
|
73
79
|
if File.exists?(file = args[0])
|
74
80
|
input = File.read(file)
|
81
|
+
gist_filename = file
|
75
82
|
gist_extension = File.extname(file) if file.include?('.')
|
76
83
|
else
|
77
84
|
abort "Can't find #{file}"
|
@@ -81,7 +88,7 @@ module Gist
|
|
81
88
|
input = $stdin.read
|
82
89
|
end
|
83
90
|
|
84
|
-
url = write(input, private_gist, gist_extension)
|
91
|
+
url = write(input, private_gist, gist_extension, gist_filename)
|
85
92
|
browse(url)
|
86
93
|
puts copy(url)
|
87
94
|
rescue => e
|
@@ -91,12 +98,13 @@ module Gist
|
|
91
98
|
end
|
92
99
|
|
93
100
|
# Create a gist on gist.github.com
|
94
|
-
def write(content, private_gist = false, gist_extension = nil)
|
101
|
+
def write(content, private_gist = false, gist_extension = nil, gist_filename = nil)
|
95
102
|
url = URI.parse(CREATE_URL)
|
96
103
|
|
97
104
|
# Net::HTTP::Proxy returns Net::HTTP if PROXY_HOST is nil
|
98
105
|
proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT)
|
99
|
-
req = proxy.post_form(url,
|
106
|
+
req = proxy.post_form(url,
|
107
|
+
data(gist_filename, gist_extension, content, private_gist))
|
100
108
|
|
101
109
|
req['Location']
|
102
110
|
end
|
@@ -117,11 +125,11 @@ module Gist
|
|
117
125
|
# Tries to copy passed content to the clipboard.
|
118
126
|
def copy(content)
|
119
127
|
cmd = case true
|
120
|
-
when system("
|
128
|
+
when system("type pbcopy > /dev/null")
|
121
129
|
:pbcopy
|
122
|
-
when system("
|
130
|
+
when system("type xclip > /dev/null")
|
123
131
|
:xclip
|
124
|
-
when system("
|
132
|
+
when system("type putclip > /dev/null")
|
125
133
|
:putclip
|
126
134
|
end
|
127
135
|
|
@@ -143,12 +151,56 @@ private
|
|
143
151
|
}.merge(private_gist ? { 'action_button' => 'private' } : {}).merge(auth)
|
144
152
|
end
|
145
153
|
|
146
|
-
# Returns a hash of the user's GitHub credentials if
|
154
|
+
# Returns a hash of the user's GitHub credentials if set.
|
147
155
|
# http://github.com/guides/local-github-config
|
148
156
|
def auth
|
149
|
-
user =
|
150
|
-
token =
|
157
|
+
user = config("github.user")
|
158
|
+
token = config("github.token")
|
151
159
|
|
152
160
|
user.empty? ? {} : { :login => user, :token => token }
|
153
161
|
end
|
162
|
+
|
163
|
+
# Returns default values based on settings in your gitconfig. See
|
164
|
+
# git-config(1) for more information.
|
165
|
+
#
|
166
|
+
# Settings applicable to gist.rb are:
|
167
|
+
#
|
168
|
+
# gist.private - boolean
|
169
|
+
# gist.extension - string
|
170
|
+
def defaults
|
171
|
+
priv = config("gist.private")
|
172
|
+
extension = config("gist.extension")
|
173
|
+
extension = nil if extension && extension.empty?
|
174
|
+
|
175
|
+
return {
|
176
|
+
"private" => priv,
|
177
|
+
"extension" => extension
|
178
|
+
}
|
179
|
+
end
|
180
|
+
|
181
|
+
# Reads a config value using git-config(1), returning something
|
182
|
+
# useful or nil.
|
183
|
+
def config(key)
|
184
|
+
str_to_bool `git config --global #{key}`.strip
|
185
|
+
end
|
186
|
+
|
187
|
+
# Parses a value that might appear in a .gitconfig file into
|
188
|
+
# something useful in a Ruby script.
|
189
|
+
def str_to_bool(str)
|
190
|
+
if str.size > 0 and str[0].chr == '!'
|
191
|
+
command = str[1, str.length]
|
192
|
+
value = `#{command}`
|
193
|
+
else
|
194
|
+
value = str
|
195
|
+
end
|
196
|
+
|
197
|
+
case value.downcase.strip
|
198
|
+
when "false", "0", "nil", "", "no", "off"
|
199
|
+
nil
|
200
|
+
when "true", "1", "yes", "on"
|
201
|
+
true
|
202
|
+
else
|
203
|
+
value
|
204
|
+
end
|
205
|
+
end
|
154
206
|
end
|
data/lib/gist/version.rb
CHANGED
data/man/gist.1
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
.\" generated with
|
2
|
-
.\" http://github.com/rtomayko/
|
1
|
+
.\" generated with Ronn/v0.4.1
|
2
|
+
.\" http://github.com/rtomayko/ronn/
|
3
3
|
.
|
4
4
|
.TH "GIST" "1" "February 2010" "GITHUB" "Gist Manual"
|
5
5
|
.
|
@@ -32,11 +32,11 @@ account if you user and token are provided (see \fBCONFIGURATION\fR).
|
|
32
32
|
These options can be used to change this behavior:
|
33
33
|
.
|
34
34
|
.TP
|
35
|
-
\fB\-p\fR, \fB\-\-private\fR
|
35
|
+
\fB\-p\fR, \fB\-\-private\fR
|
36
36
|
Create a private gist instead of a public gist.
|
37
37
|
.
|
38
38
|
.TP
|
39
|
-
\fB\-t\fR, \fB\-\-type\fR
|
39
|
+
\fB\-t\fR, \fB\-\-type\fR
|
40
40
|
Set the file extension explicitly. Passing a type of \fBrb\fR ensure
|
41
41
|
the gist is created as a Ruby file.
|
42
42
|
.
|
@@ -44,11 +44,11 @@ the gist is created as a Ruby file.
|
|
44
44
|
You may additionally ask for help:
|
45
45
|
.
|
46
46
|
.TP
|
47
|
-
\fB\-h\fR, \fB\-\-help\fR
|
47
|
+
\fB\-h\fR, \fB\-\-help\fR
|
48
48
|
Print help.
|
49
49
|
.
|
50
50
|
.TP
|
51
|
-
\fB\-m\fR, \fB\-\-man\fR
|
51
|
+
\fB\-m\fR, \fB\-\-man\fR
|
52
52
|
Display this man page.
|
53
53
|
.
|
54
54
|
.SH "CONFIGURATION"
|
@@ -57,8 +57,7 @@ Use git\-config(1) to display the currently configured GitHub username:
|
|
57
57
|
.IP "" 4
|
58
58
|
.
|
59
59
|
.nf
|
60
|
-
|
61
|
-
$ git config \-\-global github.user
|
60
|
+
$ git config \-\-global github.user
|
62
61
|
.
|
63
62
|
.fi
|
64
63
|
.
|
@@ -70,8 +69,7 @@ Or, set the GitHub username with:
|
|
70
69
|
.IP "" 4
|
71
70
|
.
|
72
71
|
.nf
|
73
|
-
|
74
|
-
$ git config \-\-global github.user <username>
|
72
|
+
$ git config \-\-global github.user <username>
|
75
73
|
.
|
76
74
|
.fi
|
77
75
|
.
|
@@ -87,8 +85,7 @@ information.
|
|
87
85
|
.IP "" 4
|
88
86
|
.
|
89
87
|
.nf
|
90
|
-
|
91
|
-
$ HTTP_PROXY=http://host:port/ gist script.py
|
88
|
+
$ HTTP_PROXY=http://host:port/ gist script.py
|
92
89
|
.
|
93
90
|
.fi
|
94
91
|
.
|
@@ -97,11 +94,10 @@ $ HTTP_PROXY=http://host:port/ gist script.py
|
|
97
94
|
.SH "EXAMPLES"
|
98
95
|
.
|
99
96
|
.nf
|
100
|
-
|
101
97
|
$ gist < file.txt
|
102
98
|
$ echo secret | gist \-\-private
|
103
99
|
$ echo "puts :hi" | gist \-t rb
|
104
|
-
$ gist script.py
|
100
|
+
$ gist script.py
|
105
101
|
.
|
106
102
|
.fi
|
107
103
|
.
|
data/man/gist.1.html
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<meta http-equiv='content-type' value='text/html;charset=utf8'>
|
5
|
-
<meta name='generator' value='
|
5
|
+
<meta name='generator' value='Ronn/v0.4.1'>
|
6
6
|
<title>gist(1) -- gist on the command line</title>
|
7
7
|
<style type='text/css'>
|
8
8
|
body {margin:0}
|
@@ -64,6 +64,7 @@
|
|
64
64
|
|
65
65
|
<h2 id='NAME'>NAME</h2>
|
66
66
|
<p><code>gist</code> -- gist on the command line</p>
|
67
|
+
|
67
68
|
<h2>SYNOPSIS</h2>
|
68
69
|
|
69
70
|
<p><code>gist</code> [<code>-p</code>] [<code>-t extension</code>] <var>FILE</var></p>
|
@@ -90,14 +91,8 @@ account if you user and token are provided (see <code>CONFIGURATION</code>).</p>
|
|
90
91
|
<p>These options can be used to change this behavior:</p>
|
91
92
|
|
92
93
|
<dl>
|
93
|
-
<dt>
|
94
|
-
<code>-
|
95
|
-
</dt>
|
96
|
-
<dd><p>Create a private gist instead of a public gist.</p></dd>
|
97
|
-
<dt>
|
98
|
-
<code>-t</code>, <code>--type</code>
|
99
|
-
</dt>
|
100
|
-
<dd><p>Set the file extension explicitly. Passing a type of <code>rb</code> ensure
|
94
|
+
<dt><code>-p</code>, <code>--private</code></dt><dd><p>Create a private gist instead of a public gist.</p></dd>
|
95
|
+
<dt><code>-t</code>, <code>--type</code></dt><dd><p>Set the file extension explicitly. Passing a type of <code>rb</code> ensure
|
101
96
|
the gist is created as a Ruby file.</p></dd>
|
102
97
|
</dl>
|
103
98
|
|
@@ -105,14 +100,8 @@ the gist is created as a Ruby file.</p></dd>
|
|
105
100
|
<p>You may additionally ask for help:</p>
|
106
101
|
|
107
102
|
<dl>
|
108
|
-
<dt>
|
109
|
-
<code>-
|
110
|
-
</dt>
|
111
|
-
<dd><p>Print help.</p></dd>
|
112
|
-
<dt>
|
113
|
-
<code>-m</code>, <code>--man</code>
|
114
|
-
</dt>
|
115
|
-
<dd><p>Display this man page.</p></dd>
|
103
|
+
<dt><code>-h</code>, <code>--help</code></dt><dd><p>Print help.</p></dd>
|
104
|
+
<dt><code>-m</code>, <code>--man</code></dt><dd><p>Display this man page.</p></dd>
|
116
105
|
</dl>
|
117
106
|
|
118
107
|
|
@@ -125,7 +114,7 @@ the gist is created as a Ruby file.</p></dd>
|
|
125
114
|
|
126
115
|
<p>Or, set the GitHub username with:</p>
|
127
116
|
|
128
|
-
<pre><code>$ git config --global github.user <username
|
117
|
+
<pre><code>$ git config --global github.user <username>
|
129
118
|
</code></pre>
|
130
119
|
|
131
120
|
<p>See <a href="http://github.com/guides/local-github-config">http://github.com/guides/local-github-config</a> for more
|
@@ -158,6 +147,7 @@ $ gist script.py
|
|
158
147
|
<a href="http://github.com">http://github.com</a>,
|
159
148
|
<a href="http://github.com/defunkt/gist">http://github.com/defunkt/gist</a></p>
|
160
149
|
|
150
|
+
|
161
151
|
<ol class='foot man'>
|
162
152
|
<li class='tl'>GITHUB</li>
|
163
153
|
<li class='tc'>February 2010</li>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-04-07 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|