gist: 44251 Download_button fork
public
Public Clone URL: git://gist.github.com/44251.git
Ruby
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
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.

Owner

hakobe

Revisions