Skip to content

Commit e43e0ce

Browse files
author
Andre Arko
committed
Merge pull request #57 from headius/d9668ffacbbb4855e15b63c5232876a011350b2c
Omit \n in piped output and make copy to clipboard optional
2 parents 04ffbef + 3951c2f commit e43e0ce

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

gist

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ module Gist
110110
gist_filename = nil
111111
gist_extension = defaults["extension"]
112112
browse_enabled = defaults["browse"]
113+
copy = defaults["copy"]
113114

114115
opts = OptionParser.new do |opts|
115116
opts.banner = "Usage: gist [options] [filename or stdin] [filename] ...\n" +
@@ -141,6 +142,10 @@ module Gist
141142
puts opts
142143
exit
143144
end
145+
146+
opts.on('-c', '--[no-]copy', 'Copy gist URL to clipboard automatically') do |c|
147+
copy = c
148+
end
144149
end
145150

146151
opts.parse!(args)
@@ -170,7 +175,8 @@ module Gist
170175

171176
url = write(files, private_gist)
172177
browse(url) if browse_enabled
173-
puts copy(url)
178+
copy(url) if copy
179+
$stdout.tty? ? puts(url) : print(url)
174180
rescue => e
175181
warn e
176182
puts opts
@@ -260,11 +266,20 @@ private
260266
def defaults
261267
extension = config("gist.extension")
262268
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
263277

264278
return {
265279
"private" => config("gist.private"),
266280
"browse" => config("gist.browse"),
267281
"extension" => extension,
282+
"copy" => copy,
268283
}
269284
end
270285

0 commit comments

Comments
 (0)