genki (owner)

Revisions

gist: 167675 Download_button fork
public
Public Clone URL: git://gist.github.com/167675.git
Embed All Files: show embed
open.rb #
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
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
    
module Termtter
  module Client
    plug 'uri-open'
    register_command(
      :name => :open, :aliases => [:o],
      :exec_proc => proc {|arg|
        sid, n = arg.split(/ +/)
        if sid.nil?
          call_commands "uri-open"
        else
          target = (n || 1).to_i
          target_uri = nil
          ids = find_status_ids(sid) || []
          ids.each do |id|
            text = Termtter::API.twitter.show(id).text
            URI.extract(text, %w[http https]).each_with_index do |uri, i|
              print "#{i + 1}) #{uri}"
              if i + 1 == target
                target_uri = uri
                print " <-"
              end
              puts ""
            end
          end
          if target_uri
            open_uri target_uri
          end
        end
      },
      :help => ['open,o', 'Open n-th URI in the message']
    )
  end
end
 
# usage
# > open $dq
# open 1st URI in $dq
# > open $dq 2
# open 2nd URI in $dq
#
# see also
# http://twitter.com/takiuchi