Permalink
Browse files

Merge branch 'master' of git://github.com/dandean/gists-tmbundle

* 'master' of git://github.com/dandean/gists-tmbundle:
  Updated private command to match new public functionality; Add correct content (selection) to private gist command; add support for whitespace in paths
  better error handling; better credential checks; allow unsaved docs to be uploaded;

Conflicts:
	Commands/Private Gist.tmCommand
	Commands/Public Gist.tmCommand
  • Loading branch information...
ivanvc committed Apr 22, 2010
2 parents 4b3c339 + dc7e7a8 commit f069d73c68cf0d0267390da585b2e96857cda432
Showing with 60 additions and 19 deletions.
  1. +31 −10 Commands/Private Gist.tmCommand
  2. +29 −9 Commands/Public 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</string>
<key>input</key>
- <string>none</string>
+ <string>selection</string>
<key>keyEquivalent</key>
<string>~@I</string>
<key>name</key>
@@ -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']}]" =&gt; ENV['TM_SELECTED_TEXT'] || contents, "login" =&gt; login, "token" =&gt; token })
-
-if response.body =~ /&lt;repo&gt;(\w+)&lt;\/repo&gt;/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}]" =&gt; contents,
+ "login" =&gt; login,
+ "token" =&gt; token
+ })
+
+ if response.body =~ /&lt;repo&gt;(\w+)&lt;\/repo&gt;/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</string>
<key>input</key>
<string>selection</string>

0 comments on commit f069d73

Please sign in to comment.