jugyo-termtter 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -9,7 +9,7 @@ bin/termtter
9
9
  lib/termtter.rb
10
10
  lib/plugin/stdout.rb
11
11
  lib/plugin/notify-send.rb
12
- lib/plugin/standard_commands.rb
12
+ lib/plugin/standard_plugins.rb
13
13
  lib/plugin/uri-open.rb
14
14
  lib/plugin/growl.rb
15
15
  lib/plugin/say.rb
data/bin/termtter CHANGED
@@ -5,7 +5,7 @@ $KCODE = 'u'
5
5
  require 'rubygems'
6
6
  require 'termtter'
7
7
  require 'configatron'
8
- plugin 'standard_commands'
8
+ plugin 'standard_plugins'
9
9
  plugin 'stdout'
10
10
 
11
11
  conf_file = File.expand_path('~/.termtter')
@@ -20,7 +20,7 @@ else
20
20
  plugins = Dir.glob(File.dirname(__FILE__) + "/../lib/plugin/*.rb").map {|f|
21
21
  f.match(%r|lib/plugin/(.*?).rb$|)[1]
22
22
  }
23
- plugins -= %w[stdout standard_commands]
23
+ plugins -= %w[stdout standard_plugins]
24
24
  plugins.each do |p|
25
25
  io.puts "#plugin '#{p}'"
26
26
  end
@@ -1,5 +1,7 @@
1
1
  module Termtter::Client
2
2
 
3
+ # standard commands
4
+
3
5
  add_command /^(update|u)\s+(.*)/ do |m, t|
4
6
  text = m[2]
5
7
  unless text.empty?
@@ -66,4 +68,51 @@ show ID Show a single status
66
68
  end
67
69
  end
68
70
 
71
+ # completion for standard commands
72
+
73
+ require 'set'
74
+ public_storage[:users] ||= Set.new
75
+ public_storage[:status_ids] ||= Set.new
76
+
77
+ add_hook do |statuses, event, t|
78
+ statuses.each do |s|
79
+ public_storage[:users].add(s.user_screen_name)
80
+ public_storage[:users] += s.text.scan(/@([a-zA-Z_0-9]*)/).flatten
81
+ public_storage[:status_ids].add(s.id.to_s)
82
+ public_storage[:status_ids].add(s.in_reply_to_status_id.to_s) if s.in_reply_to_status_id
83
+ end
84
+ end
85
+
86
+ def self.find_status_id_candidates(a, b)
87
+ if a.empty?
88
+ public_storage[:status_ids].to_a
89
+ else
90
+ public_storage[:status_ids].grep(/#{Regexp.quote a}/)
91
+ end.
92
+ map {|u| b % u }
93
+ end
94
+
95
+ def self.find_user_candidates(a, b)
96
+ if a.empty?
97
+ public_storage[:users].to_a
98
+ else
99
+ public_storage[:users].grep(/^#{Regexp.quote a}/i)
100
+ end.
101
+ map {|u| b % u }
102
+ end
103
+
104
+ add_completion do |input|
105
+ standard_commands = %w[exit help list pause update resume replies search show]
106
+ case input
107
+ when /^(list|l)?\s+(.*)/
108
+ find_user_candidates $2, "#{$1} %s"
109
+ when /^(update|u)\s+(.*)@([^\s]*)$/
110
+ find_user_candidates $3, "#{$1} #{$2}@%s"
111
+ when /^show\s+(.*)/
112
+ find_status_id_candidates $1, "show %s"
113
+ else
114
+ standard_commands.grep(/^#{Regexp.quote input}/)
115
+ end
116
+ end
117
+
69
118
  end
@@ -9,26 +9,48 @@ module Termtter::Client
9
9
  end
10
10
  end
11
11
 
12
+ def self.open_uri(uri)
13
+ # FIXME: works only in OSX and other *NIXs
14
+ if /linux/ =~ RUBY_PLATFORM
15
+ system 'firefox', uri
16
+ else
17
+ system 'open', uri
18
+ end
19
+ end
20
+
12
21
  add_command /^uri-open\s*$/ do |m, t|
13
22
  public_storage[:uris].each do |uri|
14
- # FIXME: works only in OSX and other *NIXs
15
- if /linux/ =~ RUBY_PLATFORM
16
- system 'firefox', uri
17
- else
18
- system 'open', uri
19
- end
23
+ open_uri(uri)
20
24
  end
21
25
  public_storage[:uris].clear
22
26
  end
23
27
 
28
+ add_command /^uri-open\s+(\d+)$/ do |m, t|
29
+ if m[1]
30
+ index = m[1].to_i
31
+ open_uri(public_storage[:uris][index])
32
+ public_storage[:uris].delete_at(index)
33
+ end
34
+ end
35
+
24
36
  add_command /^uri-open\s+list\s*$/ do |m, t|
25
- puts public_storage[:uris]
37
+ public_storage[:uris].each_with_index do |uri, index|
38
+ puts "#{index}: #{uri}"
39
+ end
40
+ end
41
+
42
+ add_command /^uri-open\s+delete\s+(\d+)$/ do |m, t|
43
+ public_storage[:uris].delete_at(m[1].to_i) if m[1]
26
44
  end
27
45
 
28
46
  add_command /^uri-open\s+clear\s*$/ do |m, t|
29
47
  public_storage[:uris].clear
30
48
  puts "clear uris"
31
49
  end
50
+
51
+ add_completion do |input|
52
+ ['uri-open ', 'uri-open list', 'uri-open delete', 'uri-open clear'].grep(/^#{Regexp.quote input}/)
53
+ end
32
54
  end
33
55
  # ~/.termtter
34
56
  # plugin 'uri-open'
data/lib/termtter.rb CHANGED
@@ -28,7 +28,7 @@ def require(s)
28
28
  end
29
29
 
30
30
  module Termtter
31
- VERSION = '0.5.6'
31
+ VERSION = '0.5.7'
32
32
 
33
33
  class Twitter
34
34
 
@@ -99,6 +99,7 @@ module Termtter
99
99
 
100
100
  @@hooks = []
101
101
  @@commands = {}
102
+ @@completions = []
102
103
 
103
104
  class << self
104
105
  def add_hook(&hook)
@@ -117,6 +118,21 @@ module Termtter
117
118
  @@commands.clear
118
119
  end
119
120
 
121
+ def add_completion(&completion)
122
+ @@completions << completion
123
+ end
124
+
125
+ def clear_completions
126
+ @@completions.clear
127
+ end
128
+
129
+ Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
130
+ Readline.completion_proc = proc {|input|
131
+ @@completions.map {|completion|
132
+ completion.call(input)
133
+ }.flatten.compact
134
+ }
135
+
120
136
  def public_storage
121
137
  @@public_storage ||= {}
122
138
  return @@public_storage
@@ -210,7 +226,9 @@ module Termtter
210
226
 
211
227
  @@input_thread.join
212
228
  end
229
+
213
230
  end
231
+
214
232
  end
215
233
 
216
234
  class CommandNotFound < StandardError; end
data/run_termtter.rb CHANGED
@@ -11,7 +11,7 @@ self_file =
11
11
  $:.unshift(File.dirname(self_file) + "/lib")
12
12
 
13
13
  require 'termtter'
14
- plugin 'standard_commands'
14
+ plugin 'standard_plugins'
15
15
  plugin 'stdout'
16
16
 
17
17
  configatron.update_interval
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jugyo-termtter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -64,7 +64,7 @@ files:
64
64
  - lib/termtter.rb
65
65
  - lib/plugin/stdout.rb
66
66
  - lib/plugin/notify-send.rb
67
- - lib/plugin/standard_commands.rb
67
+ - lib/plugin/standard_plugins.rb
68
68
  - lib/plugin/uri-open.rb
69
69
  - lib/plugin/growl.rb
70
70
  - lib/plugin/say.rb