diff --git a/Commands/Private Gist.tmCommand b/Commands/Private Gist.tmCommand
index c63f317..23578b1 100644
--- a/Commands/Private Gist.tmCommand
+++ b/Commands/Private Gist.tmCommand
@@ -10,21 +10,42 @@
require 'net/http'
require 'uri'
-contents = `/usr/bin/env cat "#{ENV['TM_FILEPATH']}"` unless ENV['TM_SELECTED_TEXT']
+contents = ENV['TM_SELECTED_TEXT'] || `/usr/bin/env cat "#{ENV['TM_FILEPATH']}"`
+name = ENV['TM_FILENAME'] || 'Uploaded from TextMate'
-login = `#{ENV['TM_GIT'] || "/usr/bin/env git"} config --global --get github.user`.chomp
-token = `#{ENV['TM_GIT'] || "/usr/bin/env git"} config --global --get github.token`.chomp
+if contents.nil? || contents.strip == ''
+ puts "Error: no content to upload"
-response = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), { "files[#{ENV['TM_FILENAME']}]" => ENV['TM_SELECTED_TEXT'] || contents, "private" => true, "login" => login, "token" => token })
-
-if response.body =~ /<repo>(\w+)<\/repo>/xi
- `echo -n "https://gist.github.com/#{$1}" | pbcopy`
- puts "Private Gist URL copied to clipboard"
else
- puts "Error"
+ login = `#{ENV['TM_GIT'] || "/usr/bin/env git"} config --global --get github.user`.chomp
+ token = `#{ENV['TM_GIT'] || "/usr/bin/env git"} config --global --get github.token`.chomp
+
+ if login.nil? || login == ''
+ puts "Error: your github login is not set"
+
+ elsif token.nil? || token == ''
+ puts "Error: your github token is not set"
+
+ else
+ response = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), {
+ "files[#{name}]" => contents,
+ "private" => true,
+ "login" => login,
+ "token" => token
+ })
+
+ if response.body =~ /<repo>(\w+)<\/repo>/xi
+ `echo -n "https://gist.github.com/#{$1}" | pbcopy`
+ puts "Private Gist URL copied to clipboard"
+
+ else
+ puts "Error private uploading gist"
+ end
+ end
+
end
input
- none
+ selection
keyEquivalent
~@I
name
diff --git a/Commands/Public Gist.tmCommand b/Commands/Public Gist.tmCommand
index 885f119..f587beb 100644
--- a/Commands/Public Gist.tmCommand
+++ b/Commands/Public Gist.tmCommand
@@ -10,18 +10,38 @@
require 'net/http'
require 'uri'
-contents = `/usr/bin/env cat "#{ENV['TM_FILEPATH']}"` unless ENV['TM_SELECTED_TEXT']
+contents = ENV['TM_SELECTED_TEXT'] || `/usr/bin/env cat "#{ENV['TM_FILEPATH']}"`
+name = ENV['TM_FILENAME'] || 'Uploaded from TextMate'
-login = `#{ENV['TM_GIT'] || "/usr/bin/env git"} config --global --get github.user`.chomp
-token = `#{ENV['TM_GIT'] || "/usr/bin/env git"} config --global --get github.token`.chomp
+if contents.nil? || contents.strip == ''
+ puts "Error: no content to upload"
-response = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), { "files[#{ENV['TM_FILENAME']}]" => ENV['TM_SELECTED_TEXT'] || contents, "login" => login, "token" => token })
-
-if response.body =~ /<repo>(\w+)<\/repo>/xi
- `echo -n "http://gist.github.com/#{$1}" | pbcopy`
- puts "Public Gist URL copied to clipboard"
else
- puts "Error"
+ login = `#{ENV['TM_GIT'] || "/usr/bin/env git"} config --global --get github.user`.chomp
+ token = `#{ENV['TM_GIT'] || "/usr/bin/env git"} config --global --get github.token`.chomp
+
+ if login.nil? || login == ''
+ puts "Error: your github login is not set"
+
+ elsif token.nil? || token == ''
+ puts "Error: your github token is not set"
+
+ else
+ response = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), {
+ "files[#{name}]" => contents,
+ "login" => login,
+ "token" => token
+ })
+
+ if response.body =~ /<repo>(\w+)<\/repo>/xi
+ `echo -n "http://gist.github.com/#{$1}" | pbcopy`
+ puts "Public Gist URL copied to clipboard"
+
+ else
+ puts "Error public uploading gist"
+ end
+ end
+
end
input
selection