gist 4.6.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +43 -10
- data/Rakefile +1 -3
- data/bin/gist +19 -12
- data/gist.gemspec +1 -1
- data/lib/gist.rb +115 -38
- data/spec/ghe_spec.rb +12 -5
- data/spec/rawify_spec.rb +10 -1
- data/spec/shorten_spec.rb +11 -2
- data/spec/spec_helper.rb +1 -1
- metadata +3 -8
- data/.gitignore +0 -8
- data/build/gist +0 -2357
- data/build/gist.1 +0 -258
- data/vendor/netrc.rb +0 -286
data/build/gist.1
DELETED
@@ -1,258 +0,0 @@
|
|
1
|
-
.\" generated with Ronn/v0.7.3
|
2
|
-
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
|
-
.
|
4
|
-
.TH "GIST" "1" "May 2017" "" "Gist manual"
|
5
|
-
.
|
6
|
-
.SH "NAME"
|
7
|
-
\fBgist\fR \- upload code to https://gist\.github\.com
|
8
|
-
.
|
9
|
-
.SH "Synopsis"
|
10
|
-
The gist gem provides a \fBgist\fR command that you can use from your terminal to upload content to https://gist\.github\.com/\.
|
11
|
-
.
|
12
|
-
.SH "Installation"
|
13
|
-
.
|
14
|
-
.IP "\(bu" 4
|
15
|
-
If you have ruby installed:
|
16
|
-
.
|
17
|
-
.IP
|
18
|
-
gem install gist
|
19
|
-
.
|
20
|
-
.IP "\(bu" 4
|
21
|
-
If you\'re using Bundler:
|
22
|
-
.
|
23
|
-
.IP
|
24
|
-
source :rubygems gem \'gist\'
|
25
|
-
.
|
26
|
-
.IP "\(bu" 4
|
27
|
-
For OS X, gist lives in Homebrew
|
28
|
-
.
|
29
|
-
.IP
|
30
|
-
brew install gist
|
31
|
-
.
|
32
|
-
.IP "" 0
|
33
|
-
.
|
34
|
-
.SH "Command"
|
35
|
-
.
|
36
|
-
.IP "\(bu" 4
|
37
|
-
To upload the contents of \fBa\.rb\fR just:
|
38
|
-
.
|
39
|
-
.IP
|
40
|
-
gist a\.rb
|
41
|
-
.
|
42
|
-
.IP "\(bu" 4
|
43
|
-
Upload multiple files:
|
44
|
-
.
|
45
|
-
.IP
|
46
|
-
gist a b c gist *\.rb
|
47
|
-
.
|
48
|
-
.IP "\(bu" 4
|
49
|
-
By default it reads from STDIN, and you can set a filename with \fB\-f\fR\.
|
50
|
-
.
|
51
|
-
.IP
|
52
|
-
gist \-f test\.rb <a\.rb
|
53
|
-
.
|
54
|
-
.IP "\(bu" 4
|
55
|
-
Alternatively, you can just paste from the clipboard:
|
56
|
-
.
|
57
|
-
.IP
|
58
|
-
gist \-P
|
59
|
-
.
|
60
|
-
.IP "\(bu" 4
|
61
|
-
Use \fB\-p\fR to make the gist private:
|
62
|
-
.
|
63
|
-
.IP
|
64
|
-
gist \-p a\.rb
|
65
|
-
.
|
66
|
-
.IP "\(bu" 4
|
67
|
-
Use \fB\-d\fR to add a description:
|
68
|
-
.
|
69
|
-
.IP
|
70
|
-
gist \-d "Random rbx bug" a\.rb
|
71
|
-
.
|
72
|
-
.IP "\(bu" 4
|
73
|
-
You can update existing gists with \fB\-u\fR:
|
74
|
-
.
|
75
|
-
.IP
|
76
|
-
gist \-u GIST_ID FILE_NAME gist \-u 42f2c239d2eb57299408 test\.txt
|
77
|
-
.
|
78
|
-
.IP "\(bu" 4
|
79
|
-
If you\'d like to copy the resulting URL to your clipboard, use \fB\-c\fR\.
|
80
|
-
.
|
81
|
-
.IP
|
82
|
-
gist \-c <a\.rb
|
83
|
-
.
|
84
|
-
.IP "\(bu" 4
|
85
|
-
If you\'d like to copy the resulting embeddable URL to your clipboard, use \fB\-e\fR\.
|
86
|
-
.
|
87
|
-
.IP
|
88
|
-
gist \-e <a\.rb
|
89
|
-
.
|
90
|
-
.IP "\(bu" 4
|
91
|
-
And you can just ask gist to open a browser window directly with \fB\-o\fR\.
|
92
|
-
.
|
93
|
-
.IP
|
94
|
-
gist \-o <a\.rb
|
95
|
-
.
|
96
|
-
.IP "\(bu" 4
|
97
|
-
To list (public gists or all gists for authed user) gists for user
|
98
|
-
.
|
99
|
-
.IP
|
100
|
-
gist \-l : all gists for authed user gist \-l defunkt : list defunkt\'s public gists
|
101
|
-
.
|
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
|
-
.
|
118
|
-
.IP "\(bu" 4
|
119
|
-
See \fBgist \-\-help\fR for more detail\.
|
120
|
-
.
|
121
|
-
.IP "" 0
|
122
|
-
.
|
123
|
-
.SH "Login"
|
124
|
-
If you want to associate your gists with your GitHub account, you need to login with gist\. It doesn\'t store your username and password, it just uses them to get an OAuth2 token (with the "gist" permission)\.
|
125
|
-
.
|
126
|
-
.IP "" 4
|
127
|
-
.
|
128
|
-
.nf
|
129
|
-
|
130
|
-
gist \-\-login
|
131
|
-
Obtaining OAuth2 access_token from github\.
|
132
|
-
GitHub username: ConradIrwin
|
133
|
-
GitHub password:
|
134
|
-
2\-factor auth code:
|
135
|
-
Success! https://github\.com/settings/tokens
|
136
|
-
.
|
137
|
-
.fi
|
138
|
-
.
|
139
|
-
.IP "" 0
|
140
|
-
.
|
141
|
-
.P
|
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\.
|
143
|
-
.
|
144
|
-
.IP "\(bu" 4
|
145
|
-
After you\'ve done this, you can still upload gists anonymously with \fB\-a\fR\.
|
146
|
-
.
|
147
|
-
.IP
|
148
|
-
gist \-a a\.rb
|
149
|
-
.
|
150
|
-
.IP "" 0
|
151
|
-
.
|
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
|
-
.
|
177
|
-
.TP
|
178
|
-
You can also use Gist as a library from inside your ruby code:
|
179
|
-
.
|
180
|
-
.IP
|
181
|
-
Gist\.gist("Look\.at(:my => \'awesome\')\.code")
|
182
|
-
.
|
183
|
-
.P
|
184
|
-
If you need more advanced features you can also pass:
|
185
|
-
.
|
186
|
-
.IP "\(bu" 4
|
187
|
-
\fB:access_token\fR to authenticate using OAuth2 (default is `File\.read("~/\.gist"))\.
|
188
|
-
.
|
189
|
-
.IP "\(bu" 4
|
190
|
-
\fB:filename\fR to change the syntax highlighting (default is \fBa\.rb\fR)\.
|
191
|
-
.
|
192
|
-
.IP "\(bu" 4
|
193
|
-
\fB:public\fR if you want your gist to have a guessable url\.
|
194
|
-
.
|
195
|
-
.IP "\(bu" 4
|
196
|
-
\fB:description\fR to add a description to your gist\.
|
197
|
-
.
|
198
|
-
.IP "\(bu" 4
|
199
|
-
\fB:update\fR to update an existing gist (can be a URL or an id)\.
|
200
|
-
.
|
201
|
-
.IP "\(bu" 4
|
202
|
-
\fB:anonymous\fR to submit an anonymous gist (default is false)\.
|
203
|
-
.
|
204
|
-
.IP "\(bu" 4
|
205
|
-
\fB:copy\fR to copy the resulting URL to the clipboard (default is false)\.
|
206
|
-
.
|
207
|
-
.IP "\(bu" 4
|
208
|
-
\fB:open\fR to open the resulting URL in a browser (default is false)\.
|
209
|
-
.
|
210
|
-
.IP "" 0
|
211
|
-
.
|
212
|
-
.P
|
213
|
-
NOTE: The access_token must have the "gist" scope\.
|
214
|
-
.
|
215
|
-
.IP "\(bu" 4
|
216
|
-
If you want to upload multiple files in the same gist, you can:
|
217
|
-
.
|
218
|
-
.IP
|
219
|
-
Gist\.multi_gist("a\.rb" => "Foo\.bar", "a\.py" => "Foo\.bar")
|
220
|
-
.
|
221
|
-
.IP "\(bu" 4
|
222
|
-
If you\'d rather use gist\'s builtin access_token, then you can force the user to obtain one by calling:
|
223
|
-
.
|
224
|
-
.IP
|
225
|
-
Gist\.login!
|
226
|
-
.
|
227
|
-
.IP "\(bu" 4
|
228
|
-
This will take them through the process of obtaining an OAuth2 token, and storing it in \fB~/\.gist\fR, where it can later be read by \fBGist\.gist\fR
|
229
|
-
.
|
230
|
-
.IP "" 0
|
231
|
-
.
|
232
|
-
.SH "Configuration"
|
233
|
-
.
|
234
|
-
.IP "\(bu" 4
|
235
|
-
If you\'d like \fB\-o\fR or \fB\-c\fR to be the default when you use the gist executable, add an alias to your \fB~/\.bashrc\fR (or equivalent)\. For example:
|
236
|
-
.
|
237
|
-
.IP
|
238
|
-
alias gist=\'gist \-c\'
|
239
|
-
.
|
240
|
-
.IP "\(bu" 4
|
241
|
-
If you\'d prefer gist to open a different browser, then you can export the BROWSER environment variable:
|
242
|
-
.
|
243
|
-
.IP
|
244
|
-
export BROWSER=google\-chrome
|
245
|
-
.
|
246
|
-
.IP "" 0
|
247
|
-
.
|
248
|
-
.P
|
249
|
-
If clipboard or browser integration don\'t work on your platform, please file a bug or (more ideally) a pull request\.
|
250
|
-
.
|
251
|
-
.P
|
252
|
-
If you need to use an HTTP proxy to access the internet, export the \fBHTTP_PROXY\fR or \fBhttp_proxy\fR environment variable and gist will use it\.
|
253
|
-
.
|
254
|
-
.SH "Meta\-fu"
|
255
|
-
Thanks to @defunkt and @indirect for writing and maintaining versions 1 through 3\. Thanks to @rking and @ConradIrwin for maintaining version 4\.
|
256
|
-
.
|
257
|
-
.P
|
258
|
-
Licensed under the MIT license\. Bug\-reports, and pull requests are welcome\.
|
data/vendor/netrc.rb
DELETED
@@ -1,286 +0,0 @@
|
|
1
|
-
|
2
|
-
# The netrc library (https://github.com/heroku/netrc) is reproduced below, along
|
3
|
-
# with its copyright and license:
|
4
|
-
# - https://raw.githubusercontent.com/heroku/netrc/262ef111/LICENSE.md
|
5
|
-
# - https://raw.githubusercontent.com/heroku/netrc/262ef111/lib/netrc.rb
|
6
|
-
|
7
|
-
# The MIT License (MIT)
|
8
|
-
#
|
9
|
-
# Copyright (c) 2011-2014 [CONTRIBUTORS.md](https://github.com/geemus/netrc/blob/master/CONTRIBUTORS.md)
|
10
|
-
#
|
11
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
12
|
-
# this software and associated documentation files (the "Software"), to deal in
|
13
|
-
# the Software without restriction, including without limitation the rights to
|
14
|
-
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
15
|
-
# the Software, and to permit persons to whom the Software is furnished to do so,
|
16
|
-
# subject to the following conditions:
|
17
|
-
#
|
18
|
-
# The above copyright notice and this permission notice shall be included in all
|
19
|
-
# copies or substantial portions of the Software.
|
20
|
-
#
|
21
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
23
|
-
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
24
|
-
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
25
|
-
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
26
|
-
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
-
|
28
|
-
require 'rbconfig'
|
29
|
-
require 'io/console'
|
30
|
-
|
31
|
-
class Netrc
|
32
|
-
VERSION = "0.11.0"
|
33
|
-
|
34
|
-
# see http://stackoverflow.com/questions/4871309/what-is-the-correct-way-to-detect-if-ruby-is-running-on-windows
|
35
|
-
WINDOWS = RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
|
36
|
-
CYGWIN = RbConfig::CONFIG["host_os"] =~ /cygwin/
|
37
|
-
|
38
|
-
def self.default_path
|
39
|
-
File.join(ENV['NETRC'] || home_path, netrc_filename)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.home_path
|
43
|
-
home = Dir.respond_to?(:home) ? Dir.home : ENV['HOME']
|
44
|
-
|
45
|
-
if WINDOWS && !CYGWIN
|
46
|
-
home ||= File.join(ENV['HOMEDRIVE'], ENV['HOMEPATH']) if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
|
47
|
-
home ||= ENV['USERPROFILE']
|
48
|
-
# XXX: old stuff; most likely unnecessary
|
49
|
-
home = home.tr("\\", "/") unless home.nil?
|
50
|
-
end
|
51
|
-
|
52
|
-
(home && File.readable?(home)) ? home : Dir.pwd
|
53
|
-
rescue ArgumentError
|
54
|
-
return Dir.pwd
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.netrc_filename
|
58
|
-
WINDOWS && !CYGWIN ? "_netrc" : ".netrc"
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.config
|
62
|
-
@config ||= {}
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.configure
|
66
|
-
yield(self.config) if block_given?
|
67
|
-
self.config
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.check_permissions(path)
|
71
|
-
perm = File.stat(path).mode & 0777
|
72
|
-
if perm != 0600 && !(WINDOWS) && !(Netrc.config[:allow_permissive_netrc_file])
|
73
|
-
raise Error, "Permission bits for '#{path}' should be 0600, but are "+perm.to_s(8)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Reads path and parses it as a .netrc file. If path doesn't
|
78
|
-
# exist, returns an empty object. Decrypt paths ending in .gpg.
|
79
|
-
def self.read(path=default_path)
|
80
|
-
check_permissions(path)
|
81
|
-
data = if path =~ /\.gpg$/
|
82
|
-
decrypted = if ENV['GPG_AGENT_INFO']
|
83
|
-
`gpg --batch --quiet --decrypt #{path}`
|
84
|
-
else
|
85
|
-
print "Enter passphrase for #{path}: "
|
86
|
-
STDIN.noecho do
|
87
|
-
`gpg --batch --passphrase-fd 0 --quiet --decrypt #{path}`
|
88
|
-
end
|
89
|
-
end
|
90
|
-
if $?.success?
|
91
|
-
decrypted
|
92
|
-
else
|
93
|
-
raise Error.new("Decrypting #{path} failed.") unless $?.success?
|
94
|
-
end
|
95
|
-
else
|
96
|
-
File.read(path)
|
97
|
-
end
|
98
|
-
new(path, parse(lex(data.lines.to_a)))
|
99
|
-
rescue Errno::ENOENT
|
100
|
-
new(path, parse(lex([])))
|
101
|
-
end
|
102
|
-
|
103
|
-
class TokenArray < Array
|
104
|
-
def take
|
105
|
-
if length < 1
|
106
|
-
raise Error, "unexpected EOF"
|
107
|
-
end
|
108
|
-
shift
|
109
|
-
end
|
110
|
-
|
111
|
-
def readto
|
112
|
-
l = []
|
113
|
-
while length > 0 && ! yield(self[0])
|
114
|
-
l << shift
|
115
|
-
end
|
116
|
-
return l.join
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def self.lex(lines)
|
121
|
-
tokens = TokenArray.new
|
122
|
-
for line in lines
|
123
|
-
content, comment = line.split(/(\s*#.*)/m)
|
124
|
-
content.each_char do |char|
|
125
|
-
case char
|
126
|
-
when /\s/
|
127
|
-
if tokens.last && tokens.last[-1..-1] =~ /\s/
|
128
|
-
tokens.last << char
|
129
|
-
else
|
130
|
-
tokens << char
|
131
|
-
end
|
132
|
-
else
|
133
|
-
if tokens.last && tokens.last[-1..-1] =~ /\S/
|
134
|
-
tokens.last << char
|
135
|
-
else
|
136
|
-
tokens << char
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
if comment
|
141
|
-
tokens << comment
|
142
|
-
end
|
143
|
-
end
|
144
|
-
tokens
|
145
|
-
end
|
146
|
-
|
147
|
-
def self.skip?(s)
|
148
|
-
s =~ /^\s/
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
# Returns two values, a header and a list of items.
|
154
|
-
# Each item is a tuple, containing some or all of:
|
155
|
-
# - machine keyword (including trailing whitespace+comments)
|
156
|
-
# - machine name
|
157
|
-
# - login keyword (including surrounding whitespace+comments)
|
158
|
-
# - login
|
159
|
-
# - password keyword (including surrounding whitespace+comments)
|
160
|
-
# - password
|
161
|
-
# - trailing chars
|
162
|
-
# This lets us change individual fields, then write out the file
|
163
|
-
# with all its original formatting.
|
164
|
-
def self.parse(ts)
|
165
|
-
cur, item = [], []
|
166
|
-
|
167
|
-
unless ts.is_a?(TokenArray)
|
168
|
-
ts = TokenArray.new(ts)
|
169
|
-
end
|
170
|
-
|
171
|
-
pre = ts.readto{|t| t == "machine" || t == "default"}
|
172
|
-
|
173
|
-
while ts.length > 0
|
174
|
-
if ts[0] == 'default'
|
175
|
-
cur << ts.take.to_sym
|
176
|
-
cur << ''
|
177
|
-
else
|
178
|
-
cur << ts.take + ts.readto{|t| ! skip?(t)}
|
179
|
-
cur << ts.take
|
180
|
-
end
|
181
|
-
|
182
|
-
if ts.include?('login')
|
183
|
-
cur << ts.readto{|t| t == "login"} + ts.take + ts.readto{|t| ! skip?(t)}
|
184
|
-
cur << ts.take
|
185
|
-
end
|
186
|
-
|
187
|
-
if ts.include?('password')
|
188
|
-
cur << ts.readto{|t| t == "password"} + ts.take + ts.readto{|t| ! skip?(t)}
|
189
|
-
cur << ts.take
|
190
|
-
end
|
191
|
-
|
192
|
-
cur << ts.readto{|t| t == "machine" || t == "default"}
|
193
|
-
|
194
|
-
item << cur
|
195
|
-
cur = []
|
196
|
-
end
|
197
|
-
|
198
|
-
[pre, item]
|
199
|
-
end
|
200
|
-
|
201
|
-
def initialize(path, data)
|
202
|
-
@new_item_prefix = ''
|
203
|
-
@path = path
|
204
|
-
@pre, @data = data
|
205
|
-
|
206
|
-
if @data && @data.last && :default == @data.last[0]
|
207
|
-
@default = @data.pop
|
208
|
-
else
|
209
|
-
@default = nil
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
attr_accessor :new_item_prefix
|
214
|
-
|
215
|
-
def [](k)
|
216
|
-
if item = @data.detect {|datum| datum[1] == k}
|
217
|
-
Entry.new(item[3], item[5])
|
218
|
-
elsif @default
|
219
|
-
Entry.new(@default[3], @default[5])
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def []=(k, info)
|
224
|
-
if item = @data.detect {|datum| datum[1] == k}
|
225
|
-
item[3], item[5] = info
|
226
|
-
else
|
227
|
-
@data << new_item(k, info[0], info[1])
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
def length
|
232
|
-
@data.length
|
233
|
-
end
|
234
|
-
|
235
|
-
def delete(key)
|
236
|
-
datum = nil
|
237
|
-
for value in @data
|
238
|
-
if value[1] == key
|
239
|
-
datum = value
|
240
|
-
break
|
241
|
-
end
|
242
|
-
end
|
243
|
-
@data.delete(datum)
|
244
|
-
end
|
245
|
-
|
246
|
-
def each(&block)
|
247
|
-
@data.each(&block)
|
248
|
-
end
|
249
|
-
|
250
|
-
def new_item(m, l, p)
|
251
|
-
[new_item_prefix+"machine ", m, "\n login ", l, "\n password ", p, "\n"]
|
252
|
-
end
|
253
|
-
|
254
|
-
def save
|
255
|
-
if @path =~ /\.gpg$/
|
256
|
-
e = IO.popen("gpg -a --batch --default-recipient-self -e", "r+") do |gpg|
|
257
|
-
gpg.puts(unparse)
|
258
|
-
gpg.close_write
|
259
|
-
gpg.read
|
260
|
-
end
|
261
|
-
raise Error.new("Encrypting #{@path} failed.") unless $?.success?
|
262
|
-
File.open(@path, 'w', 0600) {|file| file.print(e)}
|
263
|
-
else
|
264
|
-
File.open(@path, 'w', 0600) {|file| file.print(unparse)}
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
def unparse
|
269
|
-
@pre + @data.map do |datum|
|
270
|
-
datum = datum.join
|
271
|
-
unless datum[-1..-1] == "\n"
|
272
|
-
datum << "\n"
|
273
|
-
else
|
274
|
-
datum
|
275
|
-
end
|
276
|
-
end.join
|
277
|
-
end
|
278
|
-
|
279
|
-
Entry = Struct.new(:login, :password) do
|
280
|
-
alias to_ary to_a
|
281
|
-
end
|
282
|
-
|
283
|
-
end
|
284
|
-
|
285
|
-
class Netrc::Error < ::StandardError
|
286
|
-
end
|