Permalink
Browse files

v1.1.0

  • Loading branch information...
1 parent f0a2039 commit 1d559534b15a5f4db15b01cf44a78a01e6e3abc3 @defunkt committed Apr 7, 2010
Showing with 35 additions and 18 deletions.
  1. +34 −17 gist
  2. +1 −1 lib/gist/version.rb
View
51 gist
@@ -79,7 +79,7 @@ module Gist
end
end
module Gist
- VERSION = Version = '1.0.3'
+ VERSION = Version = '1.1.0'
end
require 'open-uri'
require 'net/http'
@@ -100,6 +100,7 @@ module Gist
def execute(*args)
private_gist = defaults["private"]
+ gist_filename = nil
gist_extension = defaults["extension"]
opts = OptionParser.new do |opts|
@@ -136,6 +137,7 @@ module Gist
if File.exists?(file = args[0])
input = File.read(file)
+ gist_filename = file
gist_extension = File.extname(file) if file.include?('.')
else
abort "Can't find #{file}"
@@ -144,7 +146,7 @@ module Gist
input = $stdin.read
end
- url = write(input, private_gist, gist_extension)
+ url = write(input, private_gist, gist_extension, gist_filename)
browse(url)
puts copy(url)
rescue => e
@@ -153,11 +155,11 @@ module Gist
end
end
- def write(content, private_gist = false, gist_extension = nil)
+ def write(content, private_gist = false, gist_extension = nil, gist_filename = nil)
url = URI.parse(CREATE_URL)
proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT)
- req = proxy.post_form(url, data(nil, gist_extension, content, private_gist))
+ req = proxy.post_form(url, data(gist_filename, gist_extension, content, private_gist))
req['Location']
end
@@ -174,11 +176,11 @@ module Gist
def copy(content)
cmd = case true
- when system("which pbcopy &> /dev/null")
+ when system("type pbcopy > /dev/null")
:pbcopy
- when system("which xclip &> /dev/null")
+ when system("type xclip > /dev/null")
:xclip
- when system("which putclip &> /dev/null")
+ when system("type putclip > /dev/null")
:putclip
end
@@ -199,27 +201,42 @@ private
end
def auth
- user = `git config --global github.user`.strip
- token = `git config --global github.token`.strip
+ user = config("github.user")
+ token = config("github.token")
user.empty? ? {} : { :login => user, :token => token }
end
def defaults
- priv = str_to_bool(`git config gist.private`.strip)
- extension = `git config gist.extension`.strip
- extension = nil if extension.empty?
+ priv = config("gist.private")
+ extension = config("gist.extension")
+ extension = nil if extension && extension.empty?
- {"private" => priv,
- "extension" => extension}
+ return {
+ "private" => priv,
+ "extension" => extension
+ }
+ end
+
+ def config(key)
+ str_to_bool `git config --global #{key}`.strip
end
def str_to_bool(str)
- case str.downcase
- when "false", "0", "nil", ""
- false
+ if str.size > 0 and str[0].chr == '!'
+ command = str[1, str.length]
+ value = `#{command}`
else
+ value = str
+ end
+
+ case value.downcase.strip
+ when "false", "0", "nil", "", "no", "off"
+ nil
+ when "true", "1", "yes", "on"
true
+ else
+ value
end
end
end
View
2 lib/gist/version.rb
@@ -1,3 +1,3 @@
module Gist
- VERSION = Version = '1.0.3'
+ VERSION = Version = '1.1.0'
end

0 comments on commit 1d55953

Please sign in to comment.