Browse files

Merge pull request #57 from headius/d9668ffacbbb4855e15b63c5232876a01…

…1350b2c

Omit \n in piped output and make copy to clipboard optional
  • Loading branch information...
2 parents 04ffbef + 3951c2f commit e43e0ce1726b01879949422580be9b953ffee539 Andre Arko committed Jul 12, 2011
Showing with 16 additions and 1 deletion.
  1. +16 −1 gist
View
17 gist
@@ -110,6 +110,7 @@ module Gist
gist_filename = nil
gist_extension = defaults["extension"]
browse_enabled = defaults["browse"]
+ copy = defaults["copy"]
opts = OptionParser.new do |opts|
opts.banner = "Usage: gist [options] [filename or stdin] [filename] ...\n" +
@@ -141,6 +142,10 @@ module Gist
puts opts
exit
end
+
+ opts.on('-c', '--[no-]copy', 'Copy gist URL to clipboard automatically') do |c|
+ copy = c
+ end
end
opts.parse!(args)
@@ -170,7 +175,8 @@ module Gist
url = write(files, private_gist)
browse(url) if browse_enabled
- puts copy(url)
+ copy(url) if copy
+ $stdout.tty? ? puts(url) : print(url)
rescue => e
warn e
puts opts
@@ -260,11 +266,20 @@ private
def defaults
extension = config("gist.extension")
extension = nil if extension && extension.empty?
+
+ copy = config("gist.copy")
+ if copy.nil?
+ copy = true
+ else
+ # match optparse boolean true states
+ copy = copy =~ /^(true)|(on)|(\+)/
+ end
return {
"private" => config("gist.private"),
"browse" => config("gist.browse"),
"extension" => extension,
+ "copy" => copy,
}
end

0 comments on commit e43e0ce

Please sign in to comment.