/
Private Gist.tmCommand
37 lines (32 loc) · 1.24 KB
/
Private Gist.tmCommand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?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>#!/usr/bin/env ruby
require 'net/http'
require 'uri'
contents = `/usr/bin/env cat #{ENV['TM_FILEPATH']}` unless ENV['TM_SELECTED_TEXT']
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
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"
end</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>~@I</string>
<key>name</key>
<string>Create Private Gist</string>
<key>output</key>
<string>showAsTooltip</string>
<key>uuid</key>
<string>E637E422-3406-49BB-A772-6E42D1AA1951</string>
</dict>
</plist>