Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to create (private) gists from a selection or file.
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?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/create_gist_from_selection.rb"</string> | ||
<key>input</key> | ||
<string>selection</string> | ||
<key>keyEquivalent</key> | ||
<string>^~@g</string> | ||
<key>name</key> | ||
<string>Create Gist from Selection</string> | ||
<key>output</key> | ||
<string>showAsTooltip</string> | ||
<key>uuid</key> | ||
<string>4D3B092F-0ABC-4152-923B-99D0B94B46B9</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?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/create_gist_from_selection.rb" "private"</string> | ||
<key>input</key> | ||
<string>selection</string> | ||
<key>keyEquivalent</key> | ||
<string>^~@g</string> | ||
<key>name</key> | ||
<string>Create private Gist from Selection</string> | ||
<key>output</key> | ||
<string>showAsTooltip</string> | ||
<key>uuid</key> | ||
<string>4F4468C5-5CF8-4272-B87C-7CF1A56B1710</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$:.unshift(File.dirname(__FILE__) + "/../lib") | ||
require "rubygems" | ||
require "gist" | ||
|
||
selection = nil | ||
if ENV['TM_SELECTED_TEXT'] | ||
selection = ENV['TM_SELECTED_TEXT'] | ||
else | ||
selection = STDIN.read | ||
end | ||
|
||
if url = Gist.write(selection, ARGV[0] == "private" ? true : false) | ||
puts "Created gist at #{url}. URL copied to clipboard." | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2008 Chris Wanstrath | ||
# Taken from defunkt's gist repository: http://github.com/defunkt/gist/tree/master | ||
|
||
require 'open-uri' | ||
require 'net/http' | ||
|
||
module Gist | ||
extend self | ||
|
||
@@gist_url = 'http://gist.github.com/%s.txt' | ||
|
||
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(content, private_gist) | ||
url = URI.parse('http://gist.github.com/gists') | ||
req = Net::HTTP.post_form(url, data(nil, nil, content, private_gist)) | ||
copy req['Location'] | ||
end | ||
|
||
private | ||
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 } | ||
end | ||
|
||
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) | ||
end | ||
|
||
def auth | ||
user = `git config --global github.user`.strip | ||
token = `git config --global github.token`.strip | ||
|
||
user.empty? ? {} : { :login => user, :token => token } | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters