jugyo-termtter 1.1.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/ChangeLog +115 -0
  2. data/README.rdoc +25 -10
  3. data/Rakefile +53 -34
  4. data/lib/plugins/cool.rb +2 -5
  5. data/lib/plugins/curry.rb +43 -0
  6. data/lib/plugins/db.rb +91 -0
  7. data/lib/plugins/{auto_reload.rb → defaults/auto_reload.rb} +5 -1
  8. data/lib/plugins/defaults/command_line.rb +111 -0
  9. data/lib/plugins/{exec.rb → defaults/exec.rb} +2 -7
  10. data/lib/plugins/{fib.rb → defaults/fib.rb} +1 -4
  11. data/lib/plugins/defaults/retweet.rb +34 -0
  12. data/lib/plugins/{standard_commands.rb → defaults/standard_commands.rb} +88 -162
  13. data/lib/plugins/defaults/standard_completion.rb +67 -0
  14. data/lib/plugins/defaults/stdout.rb +148 -0
  15. data/lib/plugins/defaults.rb +14 -0
  16. data/lib/plugins/en2ja.rb +11 -5
  17. data/lib/plugins/english.rb +2 -2
  18. data/lib/plugins/expand-tinyurl.rb +27 -6
  19. data/lib/plugins/github-issues.rb +192 -0
  20. data/lib/plugins/group.rb +30 -4
  21. data/lib/plugins/growl.rb +10 -1
  22. data/lib/plugins/http_server/favicon.ico +0 -0
  23. data/lib/plugins/http_server/index.html +117 -0
  24. data/lib/plugins/http_server.rb +82 -0
  25. data/lib/plugins/irb.rb +6 -0
  26. data/lib/plugins/l2.rb +1 -1
  27. data/lib/plugins/list_with_opts.rb +0 -3
  28. data/lib/plugins/log.rb +6 -9
  29. data/lib/plugins/modify_arg_hook_sample.rb +3 -5
  30. data/lib/plugins/multi_reply.rb +0 -5
  31. data/lib/plugins/notify-send.rb +1 -1
  32. data/lib/plugins/notify-send2.rb +1 -1
  33. data/lib/plugins/notify-send3.rb +11 -3
  34. data/lib/plugins/open_url.rb +5 -17
  35. data/lib/plugins/otsune.rb +3 -9
  36. data/lib/plugins/outputz.rb +1 -1
  37. data/lib/plugins/pool.rb +30 -0
  38. data/lib/plugins/protected_filter.rb +9 -0
  39. data/lib/plugins/quicklook.rb +1 -1
  40. data/lib/plugins/saykanji.rb +81 -0
  41. data/lib/plugins/shell.rb +1 -6
  42. data/lib/plugins/sl.rb +8 -8
  43. data/lib/plugins/tinyurl.rb +26 -7
  44. data/lib/plugins/trends.rb +84 -0
  45. data/lib/plugins/twitpic.rb +46 -0
  46. data/lib/plugins/uri-open.rb +33 -28
  47. data/lib/plugins/wassr.rb +0 -3
  48. data/lib/plugins/whois.rb +45 -0
  49. data/lib/plugins/yhara.rb +2 -6
  50. data/lib/termtter/client.rb +91 -103
  51. data/lib/termtter/command.rb +24 -9
  52. data/lib/termtter/config.rb +8 -6
  53. data/lib/termtter/config_setup.rb +1 -1
  54. data/lib/termtter/config_template.erb +1 -4
  55. data/lib/termtter/hook.rb +2 -2
  56. data/lib/termtter/optparse.rb +14 -1
  57. data/lib/termtter/system_extensions.rb +3 -2
  58. data/lib/termtter/task_manager.rb +1 -5
  59. data/lib/termtter/version.rb +1 -1
  60. data/spec/plugins/cool_spec.rb +1 -1
  61. data/spec/plugins/curry_spec.rb +13 -0
  62. data/spec/plugins/db_spec.rb +62 -0
  63. data/spec/plugins/english_spec.rb +2 -2
  64. data/spec/plugins/fib_spec.rb +2 -2
  65. data/spec/plugins/filter_spec.rb +2 -2
  66. data/spec/plugins/pause_spec.rb +1 -1
  67. data/spec/plugins/primes_spec.rb +2 -2
  68. data/spec/plugins/shell_spec.rb +1 -1
  69. data/spec/plugins/sl_spec.rb +1 -1
  70. data/spec/plugins/{standard_plugins_spec.rb → standard_commands_spec.rb} +2 -2
  71. data/spec/plugins/whois_spec.rb +20 -0
  72. data/spec/termtter/client_spec.rb +151 -33
  73. data/spec/termtter/command_spec.rb +68 -35
  74. data/spec/termtter/config_spec.rb +10 -0
  75. data/spec/termtter/optparse_spec.rb +16 -0
  76. data/spec/termtter_spec.rb +7 -8
  77. metadata +48 -19
  78. data/History.txt +0 -4
  79. data/lib/plugins/direct_messages.rb +0 -36
  80. data/lib/plugins/retweet.rb +0 -46
  81. data/lib/plugins/stdout.rb +0 -77
@@ -23,8 +23,8 @@ module Termtter::Client
23
23
  :help => ['open_url (TYPABLE|ID|@USER)', 'Open url'],
24
24
  :exec_proc => lambda {|arg|
25
25
  Thread.new(arg) do |arg|
26
- if public_storage[:typable_id] && status = typable_id_status(arg)
27
- status.text.gsub(URI.regexp) {|uri|
26
+ if status = Termtter::Client.typable_id_to_data(arg)
27
+ status.text.gsub(URI.regexp(['http', 'https'])) {|uri|
28
28
  open_uri(uri)
29
29
  }
30
30
  else
@@ -33,27 +33,15 @@ module Termtter::Client
33
33
  user = $1
34
34
  statuses = Termtter::API.twitter.user_timeline(user)
35
35
  return if statuses.empty?
36
- statuses[0].text.gsub(URI.regexp) {|uri| open_uri(uri) }
36
+ statuses[0].text.gsub(URI.regexp(['http', 'https'])) {|uri| open_uri(uri) }
37
37
  when /^\d+/
38
- Termtter::API.twitter.show(arg).text.gsub(URI.regexp) {|uri| open_uri(uri) }
38
+ Termtter::API.twitter.show(arg).text.gsub(URI.regexp(['http', 'https'])) {|uri| open_uri(uri) }
39
39
  end
40
40
  end
41
41
  end
42
- },
43
- :completion_proc => lambda {|cmd, arg|
44
- if public_storage[:typable_id] && typable_id?(arg)
45
- "#{cmd} #{typable_id_convert(arg)}"
46
- else
47
- case arg
48
- when /@(.*)/
49
- find_user_candidates $1, "#{cmd} @%s"
50
- when /(\d+)/
51
- find_status_ids(arg).map{|id| "#{cmd} #{$1}"}
52
- end
53
- end
54
42
  }
55
43
  )
56
44
  end
57
45
 
58
46
  #Optional Setting
59
- # config.plugins.open_url.browser = firefox
47
+ # config.plugins.open_url.browser = 'firefox'
@@ -1,20 +1,14 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Termtter::Client
4
- register_macro(:otsune, "update @%s 頭蓋骨の中身がお気の毒です.",
5
- :help => ['otsune {SCREENNAME}', 'update "@{SCREENNAME} 頭蓋骨の中身がお気の毒です"'],
6
- :completion_proc => lambda {|cmd, args|
7
- find_user_candidates args, "#{cmd} %s"
8
- }
4
+ register_macro(:otsune, "update %s 頭蓋骨の中身がお気の毒です.",
5
+ :help => ['otsune {SCREENNAME}', 'update "@{SCREENNAME} 頭蓋骨の中身がお気の毒です"']
9
6
  )
10
7
  end
11
8
 
12
9
  module Termtter::Client
13
10
  register_macro(:otsnue, "update @%s 頭蓋骨の中身がお気の毒です.",
14
- :help => ['otsnue {SCREENNAME}', 'update @%s 頭が気の毒です.'],
15
- :completion_proc => lambda {|cmd, args|
16
- find_user_candidates args, "#{cmd} %s"
17
- }
11
+ :help => ['otsnue {SCREENNAME}', 'update @%s 頭が気の毒です.']
18
12
  )
19
13
  end
20
14
 
@@ -30,4 +30,4 @@ end
30
30
  #
31
31
  # settings (note: must this order)
32
32
  # config.plugins.outputz.secret_key = 'your secret key'
33
- # plugin 'outputz'
33
+ # t.plug 'outputz'
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'drb/drb'
4
+ require 'rinda/tuplespace'
5
+
6
+ config.plugins.pool.set_default(:port, '12354')
7
+
8
+ pool = Rinda::TupleSpace.new
9
+ DRb.start_service("druby://:#{config.plugins.pool.port}", pool)
10
+
11
+ Thread.new do
12
+ loop do
13
+ statement = pool.take([:statement, nil])
14
+ print 'pool: '
15
+ Termtter::Client.call_commands("update #{statement[1]}")
16
+ STDOUT.flush
17
+ end
18
+ end
19
+
20
+ # pool plugin allow remote update
21
+ # e.g)
22
+ #
23
+ # require 'drb/drb'
24
+ #
25
+ # DRb.start_service
26
+ # pool = DRbObject.new_with_uri('http://localhost:12354')
27
+ # pool.write(['statement', 'hey!'])
28
+ #
29
+ # run above code and you show 'pool: updated => hey
30
+ #
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.register_hook(
4
+ :name => :protected_filter,
5
+ :point => :filter_for_output,
6
+ :exec => lambda { |statuses, event|
7
+ statuses.select { |s| !s.user.protected }
8
+ }
9
+ )
@@ -36,6 +36,6 @@ end
36
36
 
37
37
  # quicklook.rb
38
38
  # REQUIREMENTS:
39
- # plugin 'expand-tinyurl'
39
+ # t.plug 'expand-tinyurl'
40
40
  # TODO:
41
41
  # Close quicklook window automatically.
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ## Need install "SayKana" & "MeCab (UTF-8)"
4
+ ## SayKana
5
+ ## http://www.a-quest.com/aquestalk/saykana/
6
+ ## MeCab
7
+ ## http://mecab.sourceforge.net/
8
+
9
+ require 'uri'
10
+
11
+ config.plugins.saykanji.set_default(:user_to_say, [])
12
+ config.plugins.saykanji.set_default(:keyword_to_say, [])
13
+ config.plugins.saykanji.set_default(:say_speed, 100)
14
+ config.plugins.saykanji.set_default(:kana_english_dict_path, "#{Termtter::CONF_DIR}/tmp/kana_english_dict.csv")
15
+
16
+ if config.plugins.saykanji.user_to_say.empty? &&
17
+ config.plugins.saykanji.keyword_to_say.empty?
18
+ config.plugins.saykanji.keyword_to_say = /./
19
+ end
20
+
21
+ def saykanji(text, say_speed)
22
+ text_without_uri = text.gsub(URI.regexp(['http', 'https']), 'URI').
23
+ gsub('~', '〜').gsub(/[-―]/, 'ー').gsub('&', 'アンド').
24
+ delete("\n\`\'\"<>[]()|:;#")
25
+ text_wakati = `echo #{text_without_uri}|mecab -O wakati`.split(' ')
26
+ text_wakati.map!{ |i|
27
+ if /[@a-zA-Z]/ =~ i && File.file?(config.plugins.saykanji.kana_english_dict_path)
28
+ kana_english = `grep -i "\\"#{i}\\"" #{config.plugins.saykanji.kana_english_dict_path}`
29
+ unless kana_english.empty?
30
+ /^"(.+?)"/.match(kana_english).to_a[1]
31
+ else
32
+ i
33
+ end
34
+ elsif i == 'は'
35
+ 'ワ'
36
+ elsif i == 'へ'
37
+ 'エ'
38
+ else
39
+ i
40
+ end
41
+ }
42
+ text_to_say = `echo #{text_wakati.join}|mecab -O yomi`
43
+ system "SayKana", "-s", "#{say_speed}", "#{text_to_say}"
44
+ end
45
+
46
+ def say(who, text)
47
+ text_to_say = text.gsub(URI.regexp(['http', 'https']), 'U.R.I.')
48
+ voices = %w(Alex Alex Bruce Fred Ralph Agnes Kathy Vicki)
49
+ voice = voices[who.hash % voices.size]
50
+ system 'say', '-v', voice, text_to_say
51
+ end
52
+
53
+ module Termtter::Client
54
+ say_threads = []
55
+ register_hook(:name => :saykanji,
56
+ :point => :output,
57
+ :exec_proc => lambda {|statuses, event|
58
+ return unless event == :update_friends_timeline
59
+ say_threads << Thread.start do
60
+ (say_threads - [Thread.current]).each { |t| t.join }
61
+ statuses.each do |s|
62
+ if /[ぁ-んァ-ヴ一-龠]/ =~ s.text
63
+ saykanji(s.text, config.plugins.saykanji.say_speed.to_i)
64
+ else
65
+ say(s.screen_name, s.text)
66
+ end
67
+ end
68
+ end
69
+ }
70
+ )
71
+
72
+ register_hook(:name => :saykanji_filter,
73
+ :point => :filter_for_saykanji,
74
+ :exec => lambda { |statuses, event|
75
+ statuses.select do |s|
76
+ config.plugins.saykanji.user_to_say.include?(s.user.screen_name) ||
77
+ Regexp.union(*config.plugins.saykanji.keyword_to_say) =~ s.text
78
+ end
79
+ }
80
+ )
81
+ end
data/lib/plugins/shell.rb CHANGED
@@ -4,11 +4,6 @@ module Termtter::Client
4
4
  register_command :name => :shell, :aliases => [:sh],
5
5
  :help => ['shell,sh', 'Start your shell'],
6
6
  :exec_proc => lambda {|args|
7
- begin
8
- pause
9
- system ENV['SHELL'] || ENV['COMSPEC']
10
- ensure
11
- resume
12
- end
7
+ system ENV['SHELL'] || ENV['COMSPEC']
13
8
  }
14
9
  end
data/lib/plugins/sl.rb CHANGED
@@ -23,10 +23,13 @@ module Termtter
23
23
  register_command(
24
24
  :name => :ls, :aliases => [],
25
25
  :exec_proc => lambda {|arg|
26
- call_commands("list #{arg.empty? ? public_storage[:current] : arg}")
27
- },
28
- :completion_proc => lambda {|cmd, args|
29
- find_user_candidates args, "#{cmd} %s"
26
+ if arg.empty? && /\A#/ =~ public_storage[:current]
27
+ call_commands("search #{public_storage[:current]}")
28
+ elsif /\A#/ =~ arg
29
+ call_commands("search #{arg}")
30
+ else
31
+ call_commands("list #{arg.empty? ? public_storage[:current] : arg}")
32
+ end
30
33
  },
31
34
  :help => ['ls', 'Show list in current directory']
32
35
  )
@@ -35,12 +38,9 @@ module Termtter
35
38
  :name => :cd, :aliases => [],
36
39
  :exec_proc => lambda {|arg|
37
40
  public_storage[:current] =
38
- (arg.nil? || /\~/ =~ arg) ? '' : arg
41
+ (arg.nil? || /\~/ =~ arg) ? '' : normalize_as_user_name(arg)
39
42
  config.prompt = "~/#{public_storage[:current]} #{public_storage[:orig_prompt]}"
40
43
  },
41
- :completion_proc => lambda {|cmd, args|
42
- find_user_candidates args, "#{cmd} %s"
43
- },
44
44
  :help => ['cd USER', 'Change current directory']
45
45
  )
46
46
  end
@@ -1,17 +1,36 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ SHORTURL_MAKERS = [
4
+ { :host => "tinyurl.com", :format => '/api-create.php?url=%s' },
5
+ { :host => "is.gd", :format => '/api.php?longurl=%s' },
6
+ ]
7
+ TINYURL_HOOK_COMMANDS = [:update, :reply]
8
+ URI_REGEXP = URI.regexp(%w(http https ftp))
9
+
3
10
  Termtter::Client.register_hook(
4
11
  :name => :tinyurl,
5
- :points => [:modify_arg_for_update],
12
+ :points => TINYURL_HOOK_COMMANDS.map {|cmd|
13
+ "modify_arg_for_#{cmd.to_s}".to_sym
14
+ },
6
15
  :exec_proc => lambda {|cmd, arg|
7
- arg = arg.gsub(URI.regexp) do |url|
8
- if url =~ %r!^https?:!
9
- Termtter::API.connection.start('tinyurl.com', 80) do |http|
10
- http.get('/api-create.php?url=' + URI.escape(url)).body
16
+ http_class = Net::HTTP
17
+ unless config.proxy.host.nil? or config.proxy.host.empty?
18
+ http_class = Net::HTTP::Proxy(config.proxy.host,
19
+ config.proxy.port,
20
+ config.proxy.user_name,
21
+ config.proxy.password)
22
+ end
23
+ arg.gsub(URI_REGEXP) do |url|
24
+ url_enc = URI.escape(url)
25
+ result = url
26
+ SHORTURL_MAKERS.each do |site|
27
+ res = http_class.new(site[:host]).get(site[:format] % url_enc)
28
+ if res.code == '200'
29
+ result = res.body
30
+ break
11
31
  end
12
- else
13
- url
14
32
  end
33
+ result
15
34
  end
16
35
  }
17
36
  )
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'cgi'
6
+
7
+ Net::HTTP.version_1_2
8
+
9
+ module Termtter::Client
10
+ SEARCH_URI = 'search.twitter.com'
11
+ public_storage[:trends] = []
12
+
13
+ register_command :trend do |arg|
14
+ command, first, second = arg.split(/\s/)
15
+ query = []
16
+ if first
17
+ if /\A\d{4}-\d{2}-\d{2}\z/ =~ first
18
+ query << "date=#{first}"
19
+ query << "exclude=#{second}" if second
20
+ else
21
+ query << "exclude=#{first}"
22
+ end
23
+ end
24
+ case command
25
+ when 'list', nil
26
+ Net::HTTP.start(SEARCH_URI) do |http|
27
+ res = http.get('/trends.json')
28
+ show_trends JSON.parse(res.body)['trends']
29
+ end
30
+ when 'current'
31
+ Net::HTTP.start(SEARCH_URI) do |http|
32
+ query = "?#{query.join('&')}" unless query.size.zero?
33
+ res = http.get("/trends/current.json#{query}")
34
+ trends = JSON.parse(res.body)['trends']
35
+ date = trends.keys.first
36
+ puts "Trends: #{date}"
37
+ show_trends trends[date]
38
+ end
39
+ when 'daily'
40
+ Net::HTTP.start(SEARCH_URI) do |http|
41
+ query = "?#{query.join('&')}" unless query.size.zero?
42
+ res = http.get("/trends/daily.json#{query}")
43
+ trends = JSON.parse(res.body)['trends']
44
+ date = trends.keys.first
45
+ puts "Trends: #{date}"
46
+ show_trends trends[date]
47
+ end
48
+ when 'weekly'
49
+ Net::HTTP.start(SEARCH_URI) do |http|
50
+ query = "?#{query.join('&')}" unless query.size.zero?
51
+ res = http.get("/trends/weekly.json#{query}")
52
+ trends = JSON.parse(res.body)['trends']
53
+ date = trends.keys.first
54
+ puts "Trends: #{date}"
55
+ show_trends trends[date]
56
+ end
57
+ when 'show'
58
+ raise 'need number or word' if first.nil?
59
+ word = public_storage[:trends][first.to_i] || first
60
+ call_commands "search #{word}"
61
+ when /^\d$/
62
+ word = public_storage[:trends][command.to_i]
63
+ raise 'no such trend' unless word
64
+ call_commands "search #{word}"
65
+ when 'open'
66
+ raise 'nees number or word' if first.nil?
67
+ word = public_storage[:trends][first.to_i] || first
68
+ `open http://search.twitter.com/search?q=#{CGI.escape(word)}`
69
+ else
70
+ raise 'no such command'
71
+ end
72
+ end
73
+
74
+ private
75
+ def self.show_trends(trends)
76
+ public_storage[:trends].clear
77
+ max = trends.size.to_s.size
78
+ trends.each_with_index do |trend, idx|
79
+ public_storage[:trends] << trend['name']
80
+ puts "#{idx.to_s.rjust(max)}: #{trend['name']}"
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,46 @@
1
+ # = twitpic
2
+ #
3
+ # == usage
4
+ # > twitpic [MESSAGE] [IMAGE_FILE]
5
+ #
6
+ # == requirements
7
+ # * twitpic
8
+ # sudo gem install twitpic
9
+ #
10
+ # == TODO
11
+ # * スペースの混じったファイル名を扱えるようにする
12
+
13
+ gem "twitpic", ">=0.3.1"
14
+ require 'twitpic'
15
+
16
+ module Termtter::Client
17
+ register_command(
18
+ :name => :twitpic,
19
+ :help => ['twitpic [MESSAGE] [IMAGE_FILE]', 'Upload a image file to TwitPic'],
20
+ :exec => lambda do |arg|
21
+ path = arg.scan(/[^\s]+$/).flatten.first rescue nil
22
+
23
+ if path && File.exists?(path) && File.file?(path)
24
+ text = arg.gsub(/[^\s]+$/, '').strip
25
+ else
26
+ path = Termtter::CONF_DIR + '/tmp/twitpic_screencapture.png'
27
+ File.delete(path) if File.exists?(path)
28
+ puts 'Please capture screen!'
29
+ system('screencapture', '-i', '-f', path) || system('import', path) # TODO: こんなんで大丈夫かな
30
+ text = arg
31
+ end
32
+
33
+ if File.exists?(path)
34
+ puts 'Uploading...'
35
+ url = TwitPic.new(config.user_name, config.password).upload(path)[:mediaurl]
36
+ puts " => \"#{url}\""
37
+ post_message = "#{text} #{url}".strip
38
+ puts 'Post a message...'
39
+ Termtter::API.twitter.update(post_message)
40
+ puts " => \"#{post_message}\""
41
+ else
42
+ puts 'Aboat!'
43
+ end
44
+ end
45
+ )
46
+ end
@@ -8,39 +8,43 @@ module Termtter::Client
8
8
  :points => [:output],
9
9
  :exec_proc => lambda {|statuses, event|
10
10
  statuses.each do |s|
11
- public_storage[:uris] += s[:text].scan(%r|https?://[^\s]+|)
11
+ public_storage[:uris] = s[:text].scan(%r|https?://[^\s]+|) + public_storage[:uris]
12
12
  end
13
13
  }
14
14
  )
15
15
 
16
16
  def self.open_uri(uri)
17
- unless config.plugins.uri_open.browser.empty?
18
- system config.plugins.uri_open.browser, uri
19
- else
20
- case RUBY_PLATFORM
21
- when /linux/
22
- system 'firefox', uri
23
- when /mswin(?!ce)|mingw|bccwin/
24
- system 'explorer', uri
17
+ cmd =
18
+ unless config.plugins.uri_open.browser.empty?
19
+ config.plugins.uri_open.browser
25
20
  else
26
- system 'open', uri
21
+ case RUBY_PLATFORM
22
+ when /linux/; 'firefox'
23
+ when /mswin(?!ce)|mingw|bccwin/; 'explorer'
24
+ else; 'open'
25
+ end
27
26
  end
28
- end
27
+ system cmd, uri
29
28
  end
30
29
 
31
30
  register_command(
32
31
  :name => :'uri-open', :aliases => [:uo],
33
- :exec_proc => lambda{|arg|
32
+ :exec_proc => lambda {|arg|
34
33
  case arg
35
- when /^\s+$/
36
- public_storage[:uris].each do |uri|
37
- open_uri(uri)
38
- end
39
- public_storage[:uris].clear
34
+ when ''
35
+ open_uri public_storage[:uris].shift
36
+ when /^\s*all\s*$/
37
+ public_storage[:uris].
38
+ each {|uri| open_uri(uri) }.
39
+ clear
40
40
  when /^\s*list\s*$/
41
- public_storage[:uris].each_with_index do |uri, index|
42
- puts "#{index}: #{uri}"
43
- end
41
+ public_storage[:uris].
42
+ enum_for(:each_with_index).
43
+ to_a.
44
+ reverse.
45
+ each do |uri, index|
46
+ puts "#{index}: #{uri}"
47
+ end
44
48
  when /^\s*delete\s+(\d+)\s*$/
45
49
  puts 'delete'
46
50
  public_storage[:uris].delete_at($1.to_i)
@@ -48,19 +52,20 @@ module Termtter::Client
48
52
  public_storage[:uris].clear
49
53
  puts "clear uris"
50
54
  when /^\s*(\d+)\s*$/
51
- open_uri(public_storage[:uris][$1.to_i])
52
- public_storage[:uris].delete_at($1.to_i)
55
+ open_uri(public_storage[:uris].delete_at($1.to_i))
56
+ else
57
+ puts "**parse error in uri-open**"
53
58
  end
54
59
  },
55
- :completion_proc => lambda{|cmd, arg|
56
- %w(list delete clear).grep(/^#{Regexp.quote arg}/).map{|a| "#{cmd} #{a}"}
60
+ :completion_proc => lambda {|cmd, arg|
61
+ %w(all list delete clear).grep(/^#{Regexp.quote arg}/).map {|a| "#{cmd} #{a}" }
57
62
  }
58
63
  )
59
64
  end
60
- # ~/.termtter
61
- # plugin 'uri-open'
65
+ # ~/.termtter/config
66
+ # t.plug 'uri-open'
62
67
  #
63
- # see also: http://ujihisa.nowa.jp/entry/c3dd00c4e0
68
+ # see also: http://ujihisa.blogspot.com/2009/05/fixed-uri-open-of-termtter.html
64
69
  #
65
70
  # KNOWN BUG
66
- # * In Debian, exit or C-c in the termtter kills your firefox.
71
+ # * In Debian, exit or C-c in the termtter would kill your firefox.
data/lib/plugins/wassr.rb CHANGED
@@ -42,9 +42,6 @@ module Termtter::Client
42
42
  event = :wassr_friends_timeline
43
43
  print_statuses(statuses, event)
44
44
  },
45
- :completion_proc => lambda {|cmd, arg|
46
- find_user_candidates arg, "#{cmd} %s"
47
- },
48
45
  :help => ["wassr, wsr", "List the wassr timeline."]
49
46
  )
50
47
  end
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # This plugin resolve inputed domain name or IP address, like this following:
4
+ #
5
+ # > whois www.google.com
6
+ # => 66.249.89.147
7
+ # > whois 65.74.177.129
8
+ # => github.com
9
+ #
10
+ # Just same dig command:p
11
+
12
+ require 'resolv'
13
+
14
+ module Termtter::Client
15
+ register_command(
16
+ :name => :whois,
17
+ :exec_proc => lambda {|name|
18
+ resolved = whois? name
19
+ Termtter::API.twitter.update(resolved)
20
+ puts '=> ' << resolved
21
+ }
22
+ )
23
+ end
24
+
25
+ def whois?(arg)
26
+ if addr? arg
27
+ begin
28
+ Resolv.getname(arg)
29
+ rescue => e
30
+ e.message
31
+ end
32
+ else
33
+ begin
34
+ Resolv.getaddress(arg)
35
+ rescue => e
36
+ e.message
37
+ end
38
+ end
39
+ end
40
+
41
+ def addr?(arg)
42
+ Resolv::AddressRegex =~ arg
43
+ end
44
+
45
+ # vim: textwidth=78
data/lib/plugins/yhara.rb CHANGED
@@ -128,15 +128,11 @@ module Termtter::Client
128
128
  register_command(
129
129
  :name => :yhara,
130
130
  :exec_proc => lambda{|arg|
131
- text = "#{'@' if arg[0..0] != '@'}#{arg} #{Yharian::text}"
131
+ name = normalize_as_user_name(arg)
132
+ text = "@#{name} #{Yharian::text}"
132
133
  Termtter::API.twitter.update(text)
133
134
  puts "=> #{text}"
134
135
  },
135
- :completion_proc => lambda {|cmd, args|
136
- if /(.*)@([^\s]*)$/ =~ args
137
- find_user_candidates $2, "#{cmd} #{$1}@%s"
138
- end
139
- },
140
136
  :help => ["yhara (USER)", 'Post a new Yharian sentence']
141
137
  )
142
138
  end