Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for multifile gists

  • Loading branch information...
commit dca2243dccb1333504ce9b07ac8aaf8fbf80bc17 1 parent f2ab428
@teamon teamon authored
View
22 Commands/Add to multifile Gist.tmCommand
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>RUBYLIB="$TM_BUNDLE_SUPPORT/lib:$RUBYLIB"
+"${TM_RUBY:=ruby}" -- "${TM_BUNDLE_SUPPORT}/bin/add_to_multifile_gist.rb"
+</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^~@g</string>
+ <key>name</key>
+ <string>Add to multifile Gist</string>
+ <key>output</key>
+ <string>showAsTooltip</string>
+ <key>uuid</key>
+ <string>51A5A6E5-7A54-4C4E-A315-02247461D9D4</string>
+</dict>
+</plist>
View
22 Commands/Send multifile Gist.tmCommand
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>RUBYLIB="$TM_BUNDLE_SUPPORT/lib:$RUBYLIB"
+"${TM_RUBY:=ruby}" -- "${TM_BUNDLE_SUPPORT}/bin/send_multifile_gist.rb"
+</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^~@g</string>
+ <key>name</key>
+ <string>Send multifile Gist</string>
+ <key>output</key>
+ <string>showAsTooltip</string>
+ <key>uuid</key>
+ <string>C5646D06-0BE2-49EA-B672-B34F56F880EB</string>
+</dict>
+</plist>
View
22 Commands/Send private multifile Gist.tmCommand
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>RUBYLIB="$TM_BUNDLE_SUPPORT/lib:$RUBYLIB"
+"${TM_RUBY:=ruby}" -- "${TM_BUNDLE_SUPPORT}/bin/send_multifile_gist.rb" "private"
+</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^~@g</string>
+ <key>name</key>
+ <string>Send private multifile Gist</string>
+ <key>output</key>
+ <string>showAsTooltip</string>
+ <key>uuid</key>
+ <string>C8E0241B-0139-4DA0-A077-E1396148A1F9</string>
+</dict>
+</plist>
View
6 Support/bin/add_to_multifile_gist.rb
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+$:.unshift(File.dirname(__FILE__) + "/../lib")
+require "gist"
+
+Gist.process_selection
View
55 Support/bin/create_gist_from_selection.rb
@@ -3,55 +3,6 @@
$:.unshift(File.dirname(__FILE__) + "/../lib")
require "gist"
-# Add extension for supported modes based on TM_SCOPE
-# Cribbed from http://github.com/defunkt/gist.el/tree/master/gist.el
-def get_extension
- scope = ENV["TM_SCOPE"].split[0]
- case scope
- when /source\.actionscript/ : "as"
- when /source\.c/, "source.objc" : "c"
- when /source\.c\+\+/, "source.objc++" : "cpp"
- # common-lisp-mode : "el"
- when /source\.css/ : "css"
- when /source\.diff/, "meta.diff.range" : "diff"
- # emacs-lisp-mode : "el"
- when /source\.erlang/ : "erl"
- when /source\.haskell/, "text.tex.latex.haskel" : "hs"
- when /text\.html/ : "html"
- when /source\.io/ : "io"
- when /source\.java/ : "java"
- when /source\.js/ : "js"
- # jde-mode : "java"
- # js2-mode : "js"
- when /source\.lua/ : "lua"
- when /source\.ocaml/ : "ml"
- when /source\.objc/, "source.objc++" : "m"
- when /source\.perl/ : "pl"
- when /source\.php/ : "php"
- when /source\.python/ : "sc"
- when /source\.ruby/ : "rb" # Emacs bundle uses rbx
- when /text\.plain/ : "txt"
- when /source\.sql/ : "sql"
- when /source\.scheme/ : "scm"
- when /source\.smalltalk/ : "st"
- when /source\.shell/ : "sh"
- when /source\.tcl/, "text.html.tcl" : "tcl"
- when /source\.lex/ : "tex"
- when /text\.xml/, /text.xml.xsl/, /source.plist/, /text.xml.plist/ : "xml"
- else "txt"
- end
-end
-
-selection = nil
-gistname = nil
-if ENV['TM_SELECTED_TEXT']
- selection = ENV['TM_SELECTED_TEXT']
- gistname = "snippet" << "." << get_extension
-else
- selection = STDIN.read
- gistname = ENV['TM_FILEPATH'] ? ENV['TM_FILEPATH'].split('/')[-1] : "file" << "." << get_extension
-end
-
-if url = Gist.write(gistname, selection, ARGV[0] == "private" ? true : false)
- puts "Created gist at #{url}. URL copied to clipboard."
-end
+Gist.clear
+Gist.process_selection
+Gist.send(ARGV[0] == "private")
View
6 Support/bin/send_multifile_gist.rb
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+$:.unshift(File.dirname(__FILE__) + "/../lib")
+require "gist"
+
+Gist.send(ARGV[0] == "private")
View
119 Support/lib/gist.rb
@@ -8,41 +8,116 @@ module Gist
extend self
@@gist_url = 'http://gist.github.com/%s.txt'
+ @@files = []
def read(gist_id)
return help if gist_id == '-h' || gist_id.nil? || gist_id[/help/]
open(@@gist_url % gist_id).read
end
-
- def write(gistname, content, private_gist)
+
+ def add_file(name, content)
+ load_files
+ @@files << {:name => name, :content => content}
+ puts "#{name} added."
+ save_files
+ end
+
+ def send(private_gist)
+ load_files
url = URI.parse('http://gist.github.com/gists')
- req = Net::HTTP.post_form(url, data(gistname, nil, content, private_gist))
- copy req['Location']
+ req = Net::HTTP.post_form(url, data(private_gist))
+ url = copy req['Location']
+ puts "Created gist at #{url}. URL copied to clipboard."
+ clear
+ end
+
+ def clear
+ @@files = []
+ save_files
+ end
+
+ def process_selection
+ selection = nil
+ gistname = nil
+ if ENV['TM_SELECTED_TEXT']
+ selection = ENV['TM_SELECTED_TEXT']
+ gistname = "snippet" << "." << get_extension
+ else
+ selection = STDIN.read
+ gistname = ENV['TM_FILEPATH'] ? ENV['TM_FILEPATH'].split('/')[-1] : "file" << "." << get_extension
+ end
+
+ add_file(gistname, selection)
+ end
+
+ # Add extension for supported modes based on TM_SCOPE
+ # Cribbed from http://github.com/defunkt/gist.el/tree/master/gist.el
+ def get_extension
+ scope = ENV["TM_SCOPE"].split[0]
+ case scope
+ when /source\.actionscript/ : "as"
+ when /source\.c/, "source.objc" : "c"
+ when /source\.c\+\+/, "source.objc++" : "cpp"
+ # common-lisp-mode : "el"
+ when /source\.css/ : "css"
+ when /source\.diff/, "meta.diff.range" : "diff"
+ # emacs-lisp-mode : "el"
+ when /source\.erlang/ : "erl"
+ when /source\.haskell/, "text.tex.latex.haskel" : "hs"
+ when /text\.html/ : "html"
+ when /source\.io/ : "io"
+ when /source\.java/ : "java"
+ when /source\.js/ : "js"
+ # jde-mode : "java"
+ # js2-mode : "js"
+ when /source\.lua/ : "lua"
+ when /source\.ocaml/ : "ml"
+ when /source\.objc/, "source.objc++" : "m"
+ when /source\.perl/ : "pl"
+ when /source\.php/ : "php"
+ when /source\.python/ : "sc"
+ when /source\.ruby/ : "rb" # Emacs bundle uses rbx
+ when /text\.plain/ : "txt"
+ when /source\.sql/ : "sql"
+ when /source\.scheme/ : "scm"
+ when /source\.smalltalk/ : "st"
+ when /source\.shell/ : "sh"
+ when /source\.tcl/, "text.html.tcl" : "tcl"
+ when /source\.lex/ : "tex"
+ when /text\.xml/, /text.xml.xsl/, /source.plist/, /text.xml.plist/ : "xml"
+ else "txt"
+ end
end
private
+ def load_files
+ path = File.join(File.dirname(__FILE__), 'tmp_gists')
+ save_files unless File.exists?(path)
+ @@files = Marshal.load(File.read(path))
+ @@files ||= []
+ end
+
+ def save_files
+ path = File.join(File.dirname(__FILE__), 'tmp_gists')
+ File.open(path, 'w') {|f| f.puts Marshal.dump(@@files) }
+ end
+
def copy(content)
- case RUBY_PLATFORM
- when /darwin/
- return content if `which pbcopy`.strip == ''
- IO.popen('pbcopy', 'r+') { |clip| clip.puts content }
- when /linux/
- return content if `which xclip`.strip == ''
- IO.popen('xclip', 'r+') { |clip| clip.puts content }
- when /i386-cygwin/
- return content if `which putclip`.strip == ''
- IO.popen('putclip', 'r+') { |clip| clip.puts content }
- end
-
+ return content if `which pbcopy`.strip == ''
+ IO.popen('pbcopy', 'r+') { |clip| clip.puts content }
content
end
- def data(name, ext, content, private_gist)
- return {
- 'file_ext[gistfile1]' => ext,
- 'file_name[gistfile1]' => name,
- 'file_contents[gistfile1]' => content
- }.merge(private_gist ? { 'private' => 'on' } : {}).merge(auth)
+ def data(private_gist)
+ params = {}
+ @@files.each_with_index do |file, i|
+ params.merge!({
+ "file_ext[gistfile#{i+1}]" => nil,
+ "file_name[gistfile#{i+1}]" => file[:name],
+ "file_contents[gistfile#{i+1}]" => file[:content]
+ })
+ end
+ params.merge(private_gist ? { 'private' => 'on' } : {}).merge(auth)
end
def auth
View
BIN  Support/lib/tmp_gists
Binary file not shown
View
8 info.plist
@@ -10,6 +10,11 @@
<string>67262491-0033-4FF6-9AB7-46187500012D</string>
<string>------------------------------------</string>
<string>452D34DC-9122-4196-9BB1-BA571D21A8BB</string>
+ <string>4D3B092F-0ABC-4152-923B-99D0B94B46B9</string>
+ <string>4F4468C5-5CF8-4272-B87C-7CF1A56B1710</string>
+ <string>------------------------------------</string>
+ <string>51A5A6E5-7A54-4C4E-A315-02247461D9D4</string>
+ <string>C5646D06-0BE2-49EA-B672-B34F56F880EB</string>
</array>
<key>submenus</key>
<dict/>
@@ -23,6 +28,9 @@
<string>4D3B092F-0ABC-4152-923B-99D0B94B46B9</string>
<string>4F4468C5-5CF8-4272-B87C-7CF1A56B1710</string>
<string>452D34DC-9122-4196-9BB1-BA571D21A8BB</string>
+ <string>51A5A6E5-7A54-4C4E-A315-02247461D9D4</string>
+ <string>C5646D06-0BE2-49EA-B672-B34F56F880EB</string>
+ <string>C8E0241B-0139-4DA0-A077-E1396148A1F9</string>
</array>
<key>uuid</key>
<string>D79413BD-058B-4D38-9A99-776E2088932F</string>
Please sign in to comment.
Something went wrong with that request. Please try again.