@@ -110,6 +110,7 @@ module Gist
110
110
gist_filename = nil
111
111
gist_extension = defaults [ "extension" ]
112
112
browse_enabled = defaults [ "browse" ]
113
+ copy = defaults [ "copy" ]
113
114
114
115
opts = OptionParser . new do |opts |
115
116
opts . banner = "Usage: gist [options] [filename or stdin] [filename] ...\n " +
@@ -141,6 +142,10 @@ module Gist
141
142
puts opts
142
143
exit
143
144
end
145
+
146
+ opts . on ( '-c' , '--[no-]copy' , 'Copy gist URL to clipboard automatically' ) do |c |
147
+ copy = c
148
+ end
144
149
end
145
150
146
151
opts . parse! ( args )
@@ -170,7 +175,8 @@ module Gist
170
175
171
176
url = write ( files , private_gist )
172
177
browse ( url ) if browse_enabled
173
- puts copy ( url )
178
+ copy ( url ) if copy
179
+ $stdout. tty? ? puts ( url ) : print ( url )
174
180
rescue => e
175
181
warn e
176
182
puts opts
@@ -260,11 +266,20 @@ private
260
266
def defaults
261
267
extension = config ( "gist.extension" )
262
268
extension = nil if extension && extension . empty?
269
+
270
+ copy = config ( "gist.copy" )
271
+ if copy . nil?
272
+ copy = true
273
+ else
274
+ # match optparse boolean true states
275
+ copy = copy =~ /^(true)|(on)|(\+ )/
276
+ end
263
277
264
278
return {
265
279
"private" => config ( "gist.private" ) ,
266
280
"browse" => config ( "gist.browse" ) ,
267
281
"extension" => extension ,
282
+ "copy" => copy ,
268
283
}
269
284
end
270
285
0 commit comments