Permalink
Browse files

It can now send all the file as a gist

  • Loading branch information...
1 parent 0bfc5d0 commit 69ff8397b73e076bc72e327bbddb6751122ea72f @ivanvc committed Jul 2, 2009
Showing with 6 additions and 20 deletions.
  1. +3 −10 Commands/Private Gist.tmCommand
  2. +3 −10 Commands/Public Gist.tmCommand
View
13 Commands/Private Gist.tmCommand
@@ -10,22 +10,15 @@
require 'net/http'
require 'uri'
-unless ENV['TM_SELECTED_TEXT']
- puts "You must select something to generate a gist"
- exit
-end
+contents = `/usr/bin/env cat #{ENV['TM_FILEPATH']}` unless ENV['TM_SELECTED_TEXT']
-file = ENV['TM_FILEPATH'].match(/^\/.*\/(\w+(?:\.\w+)*)$/)[1]
login = `/usr/bin/env git config --global --get github.user`.chomp
token = `/usr/bin/env git config --global --get github.token`.chomp
-response = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), { "files[#{file}]" => ENV['TM_SELECTED_TEXT'], "private" => true, "login" => login, "token" => token })
+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
- `osascript -e 'tell application "System Events"
- set xfr_clip to "https://gist.github.com/#{$1}"
- set the clipboard to ((xfr_clip) as text)
- end tell'`
+ `echo -n "https://gist.github.com/#{$1}" | pbcopy`
puts "Private Gist URL copied to clipboard"
else
puts "Error"
View
13 Commands/Public Gist.tmCommand
@@ -10,22 +10,15 @@
require 'net/http'
require 'uri'
-unless ENV['TM_SELECTED_TEXT']
- puts "You must select something to generate a gist"
- exit
-end
+contents = `/usr/bin/env cat #{ENV['TM_FILEPATH']}` unless ENV['TM_SELECTED_TEXT']
-file = ENV['TM_FILEPATH'].match(/^\/.*\/(\w+(?:\.\w+)*)$/)[1]
login = `/usr/bin/env git config --global --get github.user`.chomp
token = `/usr/bin/env git config --global --get github.token`.chomp
-response = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), { "files[#{file}]" => ENV['TM_SELECTED_TEXT'], "login" => login, "token" => token })
+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
- `osascript -e 'tell application "System Events"
- set xfr_clip to "http://gist.github.com/#{$1}"
- set the clipboard to ((xfr_clip) as text)
- end tell'`
+ `echo -n "http://gist.github.com/#{$1}" | pbcopy`
puts "Public Gist URL copied to clipboard"
else
puts "Error"

0 comments on commit 69ff839

Please sign in to comment.