Skip to content

Instantly share code, notes, and snippets.

@thinca thinca/vim.cgi
Last active Sep 4, 2015

Embed
What would you like to do?
#!/usr/bin/env ruby
"
execute 'help' getline(1)
.,/[^*]$//\*\S\+\*$\|\%$/?^[^=-].*[^=-]$?print
qall!
"
require 'rubygems'
require 'json'
require 'cgi'
TEMP = './temp'
cgi = CGI.new
json = JSON.parse(cgi["json"])
print cgi.header('type' => 'text/plain', 'charset' => 'utf-8')
text = json['events'][0]['message']['text']
if text =~ /^:h(?:e(?:lp?)?)?\s+(\||[^|\s]+)/
keyword = $1
open(TEMP, 'w'){|f| f.write(keyword)}
result = `vim -Z -u NONE -N -e -s #{TEMP} < #{__FILE__}`
if result == ''
print 'http://gyazo.com/f71ba83245a2f0d41031033de1c57109.png'
else
print result[0, 1000]
end
File.delete(TEMP)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.