├── Commands ├── Private Gist.tmCommand └── Public Gist.tmCommand ├── MIT-LICENSE ├── README.textile ├── Support └── gist.rb └── info.plist /Commands/Private Gist.tmCommand: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | beforeRunningCommand 6 | nop 7 | command 8 | #!/usr/bin/env ruby 9 | 10 | require ENV['TM_BUNDLE_SUPPORT'] + '/gist.rb' 11 | 12 | if @continue 13 | response = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), { 14 | "files[#{@name}]" => @contents, 15 | "private" => true, 16 | "login" => @login, 17 | "token" => @token 18 | }) 19 | 20 | if response.body =~ /<repo>(\w+)<\/repo>/xi 21 | `echo -n "https://gist.github.com/#{$1}" | pbcopy` 22 | puts "Private Gist URL copied to clipboard" 23 | else 24 | puts "Error uploading private gist" 25 | end 26 | end 27 | 28 | input 29 | selection 30 | keyEquivalent 31 | ~@I 32 | name 33 | Create Private Gist 34 | output 35 | showAsTooltip 36 | uuid 37 | E637E422-3406-49BB-A772-6E42D1AA1951 38 | 39 | 40 | -------------------------------------------------------------------------------- /Commands/Public Gist.tmCommand: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | beforeRunningCommand 6 | nop 7 | command 8 | #!/usr/bin/env ruby 9 | 10 | require ENV['TM_BUNDLE_SUPPORT'] + '/gist.rb' 11 | 12 | if @continue 13 | response = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), { 14 | "files[#{@name}]" => @contents, 15 | "login" => @login, 16 | "token" => @token 17 | }) 18 | 19 | if response.body =~ /<repo>(\w+)<\/repo>/xi 20 | `echo -n "http://gist.github.com/#{$1}" | pbcopy` 21 | puts "Public Gist URL copied to clipboard" 22 | else 23 | puts "Error uploading public gist" 24 | end 25 | end 26 | 27 | input 28 | selection 29 | keyEquivalent 30 | ~@U 31 | name 32 | Create Public Gist 33 | output 34 | showAsTooltip 35 | uuid 36 | 2759C467-E0AD-488D-A37C-D8E978DEE9AB 37 | 38 | 39 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Iván Valdés Castillo 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. TextMate Bundle to create Public/Private Gists 2 | 3 | With this bundle you can simply create public and private gists. You need to have Ruby, and configured your GitHub username and token in your global config. The URL will be copied to the clipboard. 4 | 5 | h2. Pre-requisites 6 | 7 | * Install ruby 8 | * Configure your "GitHub account":https://github.com/account 9 | * If for some reason your git binary is in a place that /usr/bin/env cannot locate, then you can set it to a TextMate Shell variable (`TM_GIT`), or add the path its in to `PATH`. For example, if you installed git from MacPorts, you would add `/opt/local/bin:` to the front of `PATH`, 10 | * add your github username and token to your git config: 11 |
12 | 
13 |   $ git config --global github.user [your username]
14 |   $ git config --global github.token [your token]
15 | 
16 | 
17 | **or** to your shell environment: 18 |
19 | 
20 |   export GITHUB_USER="[your username]"
21 |   export GITHUB_TOKEN="[your token]"
22 | 
23 | 
24 | 25 | h2. Install 26 |
27 | 
28 | mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
29 | cd ~/Library/Application\ Support/TextMate/Bundles
30 | git clone git://github.com/ivanvc/gists-tmbundle.git Gists.tmbundle
31 | osascript -e 'tell app "TextMate" to reload bundles'
32 | 
33 | 
34 | 35 | h2. That's it 36 | 37 | * Use ⌘⌥⇧I to create a private gist 38 | * Use ⌘⌥⇧U to create a public gist 39 | 40 | h2. Note 41 | 42 | If setting your user/token in your shell environment, TextMate must be launched via the command line `mate` command, NOT from the dock or Finder. Otherwise it won't pick up the variables (strange behavior on TextMate's part). 43 | 44 | h2. Credits 45 | 46 | Thanks to "jjb":http://github.com/jjb, "dandean":http://github.com/dandean, and "beaucollins":http://github.com/beaucollins for their contributions. 47 | -------------------------------------------------------------------------------- /Support/gist.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | require 'uri' 3 | 4 | git_binary = ENV['TM_GIT'] || "/usr/bin/env git" 5 | github_config_get = "#{git_binary} config --global --get github" 6 | 7 | @login = ENV['GITHUB_USER'] || `#{github_config_get}.user`.chomp 8 | @token = ENV['GITHUB_TOKEN'] || `#{github_config_get}.token`.chomp 9 | 10 | @continue = true 11 | 12 | if @login.nil? || @login == '' 13 | print "\nError: your github login is not set. See https://github.com/ivanvc/gists-tmbundle for configuration instructions.\n" 14 | @continue = false 15 | end 16 | if @token.nil? || @token == '' 17 | print "\nError: your github token is not set. See https://github.com/ivanvc/gists-tmbundle for configuration instructions.\n" 18 | @continue = false 19 | end 20 | 21 | @contents = ENV['TM_SELECTED_TEXT'] || `/usr/bin/env cat "#{ENV['TM_FILEPATH']}"` 22 | @name = ENV['TM_FILENAME'] || 'Uploaded from TextMate' 23 | 24 | if @contents.nil? || @contents.strip == '' 25 | puts "Error: no content to upload" 26 | @continue = false 27 | end 28 | -------------------------------------------------------------------------------- /info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Gist 7 | ordering 8 | 9 | E637E422-3406-49BB-A772-6E42D1AA1951 10 | 2759C467-E0AD-488D-A37C-D8E978DEE9AB 11 | 12 | uuid 13 | 8669948D-C9F0-4321-B1CD-BE118E88E37F 14 | 15 | 16 | --------------------------------------------------------------------------------