Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created Jan 7, 2009
Embed
What would you like to do?
require 'open-uri'
require 'pathname'
require 'tmpdir'
configatron.plugins.quicklook.set_default(:quicklook_tmpdir, "#{Dir.tmpdir}/termtter-quicklook-tmpdir")
tmpdir = Pathname.new(configatron.plugins.quicklook.quicklook_tmpdir)
tmpdir.mkdir unless tmpdir.exist?
def quicklook(url)
tmpdir = Pathname.new(configatron.plugins.quicklook.quicklook_tmpdir)
path = tmpdir + Pathname.new(url).basename
Thread.new do
open(path, 'w') do |f|
f.write(open(url).read)
end
system("qlmanage -p #{path} > /dev/null 2>&1")
end
end
module Termtter::Client
add_command %r'^(?:quicklook|ql)\s+(\w+)$' do |m,t|
id = m[1]
status = t.show(id).first
if (status)
uris = URI.regexp.match(status.text).to_a
quicklook(uris.first) unless uris.empty?
end
end
end
# quicklook.rb
# TODO:
# Close quicklook window automatically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment