Skip to content

Instantly share code, notes, and snippets.

@thinca
Last active September 4, 2015 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thinca/246444 to your computer and use it in GitHub Desktop.
Save thinca/246444 to your computer and use it in GitHub Desktop.
#!/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