jugyo-termtter 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/README.rdoc +9 -0
  2. data/Rakefile +46 -64
  3. data/lib/filter/url_addspace.rb +16 -0
  4. data/lib/plugin/april_fool.rb +1 -1
  5. data/lib/plugin/bomb.rb +1 -1
  6. data/lib/plugin/clear.rb +14 -0
  7. data/lib/plugin/confirm.rb +1 -1
  8. data/lib/plugin/cool.rb +1 -1
  9. data/lib/plugin/devel.rb +13 -0
  10. data/lib/plugin/erb.rb +1 -1
  11. data/lib/plugin/filter.rb +4 -4
  12. data/lib/plugin/follow.rb +5 -5
  13. data/lib/plugin/grass.rb +27 -0
  14. data/lib/plugin/group.rb +8 -4
  15. data/lib/plugin/growl.rb +1 -1
  16. data/lib/plugin/hatebu.rb +2 -2
  17. data/lib/plugin/history.rb +9 -0
  18. data/lib/plugin/log.rb +14 -6
  19. data/lib/plugin/modify_arg_hook_sample.rb +1 -1
  20. data/lib/plugin/otsune.rb +2 -2
  21. data/lib/plugin/plugin.rb +3 -3
  22. data/lib/plugin/post_exec_hook_sample.rb +1 -1
  23. data/lib/plugin/pre_exec_hook_sample.rb +1 -1
  24. data/lib/plugin/reblog.rb +2 -2
  25. data/lib/plugin/scrape.rb +2 -2
  26. data/lib/plugin/shell.rb +1 -1
  27. data/lib/plugin/sl.rb +6 -6
  28. data/lib/plugin/standard_plugins.rb +62 -44
  29. data/lib/plugin/system_status.rb +2 -2
  30. data/lib/plugin/update_editor.rb +1 -1
  31. data/lib/plugin/wassr_post.rb +1 -1
  32. data/lib/plugin/yhara.rb +2 -2
  33. data/lib/plugin/yonda.rb +9 -9
  34. data/lib/termtter/client.rb +24 -7
  35. data/lib/termtter/command.rb +2 -2
  36. data/lib/termtter/hook.rb +1 -1
  37. data/lib/termtter/task.rb +1 -1
  38. data/lib/termtter/twitter.rb +51 -27
  39. data/lib/termtter/version.rb +1 -1
  40. data/spec/plugin/cool_spec.rb +10 -0
  41. data/spec/plugin/fib_spec.rb +16 -0
  42. data/spec/plugin/filter_spec.rb +18 -0
  43. data/spec/plugin/plugin_spec.rb +25 -0
  44. data/spec/plugin/shell_spec.rb +10 -0
  45. data/spec/plugin/spam_spec.rb +17 -0
  46. data/spec/plugin/standard_plugins_spec.rb +31 -0
  47. data/spec/spec_helper.rb +4 -0
  48. data/spec/termtter/client_spec.rb +175 -0
  49. data/spec/termtter/command_spec.rb +161 -0
  50. data/spec/termtter/task_manager_spec.rb +78 -0
  51. data/spec/termtter/task_spec.rb +22 -0
  52. data/spec/termtter/user_spec.rb +27 -0
  53. data/spec/termtter_spec.rb +43 -0
  54. metadata +40 -42
  55. data/Manifest.txt +0 -77
  56. data/PostInstall.txt +0 -1
  57. data/run_termtter.rb +0 -17
data/README.rdoc CHANGED
@@ -62,6 +62,15 @@ http://www.lingr.com/room/termtter
62
62
 
63
63
  http://wiki.github.com/jugyo/termtter/home (in Japanese)
64
64
 
65
+ == TODO:
66
+
67
+ - newgem を使わないようにする
68
+ - rubytter を使うようにする
69
+ - filter と plugin を統一する
70
+ - plugin => plugins (ディレクトリ名変更)
71
+ - $HOME 以下に plugin 用のディレクトリを置けるようにする
72
+ - コマンドラインオプションでいろいろ指定できるようにする
73
+
65
74
  == LICENSE:
66
75
 
67
76
  (The MIT License)
data/Rakefile CHANGED
@@ -1,64 +1,46 @@
1
- %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
- require File.dirname(__FILE__) + '/lib/termtter'
3
-
4
- # Generate all the Rake tasks
5
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
- $hoe = Hoe.new('termtter', Termtter::VERSION) do |p|
7
- p.author = %w[jugyo hakobe motemen koichiro Sixeight mattn ujihisa yanbe hitode909 bubblegum].sort_by{|i|i.downcase}
8
- p.email = ['jugyo.org@gmail.com']
9
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
10
- p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
11
- p.rubyforge_name = p.name # TODO this is default value
12
- p.extra_deps = [
13
- ['json_pure'],
14
- ['configatron'],
15
- ['highline'],
16
- ]
17
- #p.extra_dev_deps = [
18
- # ['newgem', ">= #{::Newgem::VERSION}"]
19
- #]
20
-
21
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
22
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
23
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
24
- p.rsync_args = '-av --delete --ignore-errors'
25
- end
26
-
27
- require 'newgem/tasks' # load /tasks/*.rake
28
- Dir['tasks/**/*.rake'].each { |t| load t }
29
-
30
- # TODO - want other tests/tasks run by default? Add them to the list
31
- # task :default => [:spec, :features]
32
-
33
- require 'spec/rake/spectask'
34
- desc 'run all specs'
35
- Spec::Rake::SpecTask.new do |t|
36
- t.spec_files = FileList['spec/**/*_spec.rb']
37
- t.spec_opts = ['-c']
38
- end
39
-
40
- def egrep(pattern)
41
- res = []
42
- Dir['**/*.rb'].each do |fn|
43
- count = 0
44
- open(fn) do |f|
45
- while line = f.gets
46
- count += 1
47
- if line =~ pattern
48
- res << [fn, count.to_s, line.gsub(/\A\s+/, '')]
49
- end
50
- end
51
- end
52
- end
53
- fmax = res.map {|i| i[0] }.map(&:size).max
54
- cmax = res.map {|i| i[1] }.map(&:size).max
55
- res.each do |fn, count, line|
56
- puts "%s :%s:%s" % [fn.ljust(fmax), count.rjust(cmax), line]
57
- end
58
- end
59
-
60
- desc "Look for TODO and FIXME tags in the code"
61
- task :todo do
62
- egrep /(FIXME|TODO)/
63
- end
64
-
1
+ $:.unshift File.dirname(__FILE__) + '/lib'
2
+ require 'termtter'
3
+
4
+ require 'spec/rake/spectask'
5
+ desc 'run all specs'
6
+ Spec::Rake::SpecTask.new do |t|
7
+ t.spec_files = FileList['spec/**/*_spec.rb']
8
+ t.spec_opts = ['-c']
9
+ end
10
+
11
+ desc 'Generate gemspec'
12
+ task :gemspec do |t|
13
+ open('termtter.gemspec', "wb" ) do |file|
14
+ file << <<-EOS
15
+ Gem::Specification.new do |s|
16
+ s.name = 'termtter'
17
+ s.version = '#{Termtter::VERSION}'
18
+ s.summary = "Terminal based Twitter client"
19
+ s.description = "Termtter is a terminal based Twitter client"
20
+ s.files = %w( #{Dir['lib/**/*.rb'].join(' ')}
21
+ #{Dir['spec/**/*.rb'].join(' ')}
22
+ #{Dir['test/**/*.rb', 'test/**/*.json'].join(' ')}
23
+ README.rdoc
24
+ History.txt
25
+ Rakefile )
26
+ s.executables = ["kill_termtter", "termtter"]
27
+ s.add_dependency("json_pure", ">= 1.1.3")
28
+ s.add_dependency("configatron", ">= 2.2.2")
29
+ s.add_dependency("highline", ">= 1.5.0")
30
+ s.authors = %w(jugyo ujihisa)
31
+ s.email = 'jugyo.org@gmail.com'
32
+ s.homepage = 'http://wiki.github.com/jugyo/termtter'
33
+ s.rubyforge_project = 'termtter'
34
+ s.has_rdoc = true
35
+ s.rdoc_options = ["--main", "README.rdoc", "--exclude", "spec"]
36
+ s.extra_rdoc_files = ["README.rdoc", "History.txt"]
37
+ end
38
+ EOS
39
+ end
40
+ puts "Generate gemspec"
41
+ end
42
+
43
+ desc 'Generate gem'
44
+ task :gem => :gemspec do |t|
45
+ system 'gem', 'build', 'termtter.gemspec'
46
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter::Client
4
+ add_filter do |statuses|
5
+ statuses.each do |s|
6
+ s.text.gsub!(/(\S)(https?:\/\/)/, '\1 \2')
7
+ end
8
+ statuses
9
+ end
10
+ end
11
+
12
+ # url_addspace
13
+ # add space before URL without space
14
+ # example:
15
+ # before: ABCDEhttp://~~~
16
+ # after: ABCDE http://~~~
@@ -5,7 +5,7 @@ def april_fool;april_fool? ? "今日はエイプリルフールではありま
5
5
 
6
6
  Termtter::Client.register_command(
7
7
  :name => :april_fool, :aliases => [:af],
8
- :exec_proc => proc {|arg|
8
+ :exec_proc => lambda {|arg|
9
9
  if arg =~ /^\?you\s(\w+)/
10
10
  puts "=> #{Termtter::Client.update_status("@#{$1} #{april_fool}")}"
11
11
  else
data/lib/plugin/bomb.rb CHANGED
@@ -10,7 +10,7 @@ module Termtter
10
10
  module Client
11
11
  register_command(
12
12
  :name => :bomb, :aliases => [],
13
- :exec_proc => proc {|arg|
13
+ :exec_proc => lambda {|arg|
14
14
  text = "#{arg.strip} 爆発しろ!"
15
15
  Termtter::API::twitter.update_status(text)
16
16
  puts "=> #{text}"
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter::Client
4
+ register_command :name => :clear, :aliases => [:cls],
5
+ :help => ['clear,cls', "Clear termtter's buffer"],
6
+ :exec_proc => lambda {|args|
7
+ system 'clear'
8
+ }
9
+ end
10
+
11
+ # todo:
12
+ # support windows.
13
+ # i don't have windows machine and cannot test:P
14
+ # cls command?
@@ -3,7 +3,7 @@
3
3
  Termtter::Client.register_hook(
4
4
  :name => :confirm,
5
5
  :points => [:pre_exec_update],
6
- :exec_proc => proc {|cmd, arg|
6
+ :exec_proc => lambda {|cmd, arg|
7
7
  false if arg.empty? || /^y?$/i !~ Readline.readline("update? #{arg} [Y/n] ", false)
8
8
  }
9
9
  )
data/lib/plugin/cool.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Termtter::Client
4
4
  register_macro(:cool, "update @%s cool.",
5
5
  :help => ['cool {SCREENNAME}', 'update "@{SCREENNAME} cool."'],
6
- :completion_proc => proc {|cmd, args|
6
+ :completion_proc => lambda {|cmd, args|
7
7
  find_user_candidates args, "#{cmd} %s"
8
8
  }
9
9
  )
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter::Client
4
+ register_command(
5
+ :name => :eval,
6
+ :aliases => [],
7
+ :exec_proc => lambda {|arg|
8
+ result = eval(arg) unless arg.empty?
9
+ puts "=> #{result.inspect}"
10
+ },
11
+ :help => ['eval EXPR', 'evaluate expression']
12
+ )
13
+ end
data/lib/plugin/erb.rb CHANGED
@@ -5,7 +5,7 @@ require 'erb'
5
5
  Termtter::Client.register_hook(
6
6
  :name => :erb,
7
7
  :points => [:pre_exec_update],
8
- :exec_proc => proc {|cmd, arg|
8
+ :exec_proc => lambda {|cmd, arg|
9
9
  ERB.new(arg).result(binding)
10
10
  }
11
11
  )
data/lib/plugin/filter.rb CHANGED
@@ -9,7 +9,7 @@ module Termtter::Client
9
9
 
10
10
  register_command(
11
11
  :name => :filter, :aliases => [],
12
- :exec_proc => proc {|arg|
12
+ :exec_proc => lambda {|arg|
13
13
  begin
14
14
  result = filter arg.strip
15
15
  rescue LoadError
@@ -18,7 +18,7 @@ module Termtter::Client
18
18
  puts "=> #{result.inspect}"
19
19
  end
20
20
  },
21
- :completion_proc => proc {|cmd, args|
21
+ :completion_proc => lambda {|cmd, args|
22
22
  find_filter_candidates args, "#{cmd} %s", filters
23
23
  },
24
24
  :help => ['filter FILE', 'Apply a filter']
@@ -26,7 +26,7 @@ module Termtter::Client
26
26
 
27
27
  register_command(
28
28
  :name => :unfilter, :aliases => [],
29
- :exec_proc => proc {|arg|
29
+ :exec_proc => lambda {|arg|
30
30
  clear_filters
31
31
  public_storage[:filters].clear
32
32
  puts '=> filter cleared'
@@ -36,7 +36,7 @@ module Termtter::Client
36
36
 
37
37
  register_command(
38
38
  :name => :filters, :aliases => [],
39
- :exec_proc => proc {|arg|
39
+ :exec_proc => lambda {|arg|
40
40
  unless public_storage[:filters].empty?
41
41
  puts public_storage[:filters].join(', ')
42
42
  else
data/lib/plugin/follow.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Termtter::Client
4
4
  register_command(
5
5
  :name => :follow, :aliases => [],
6
- :exec_proc => proc {|arg|
6
+ :exec_proc => lambda {|arg|
7
7
  if arg =~ /^(\w+)/
8
8
  res = Termtter::API::twitter.social($1.strip, :follow)
9
9
  if res.code == '200'
@@ -13,7 +13,7 @@ module Termtter::Client
13
13
  end
14
14
  end
15
15
  },
16
- :completion_proc => proc {|cmd, args|
16
+ :completion_proc => lambda {|cmd, args|
17
17
  find_user_candidates args, "#{cmd} %s"
18
18
  },
19
19
  :help => ['follow USER', 'Follow user']
@@ -21,9 +21,9 @@ module Termtter::Client
21
21
 
22
22
  register_command(
23
23
  :name => :leave, :aliases => [],
24
- :exec_proc => proc {|arg|
24
+ :exec_proc => lambda {|arg|
25
25
  if arg =~ /^(\w+)/
26
- res = t.social($1.strip, :leave)
26
+ res = Termtter::API::twitter.social($1.strip, :leave)
27
27
  if res.code == '200'
28
28
  puts "Leaved user @#{$1}"
29
29
  else
@@ -31,7 +31,7 @@ module Termtter::Client
31
31
  end
32
32
  end
33
33
  },
34
- :completion_proc => proc {|cmd, args|
34
+ :completion_proc => lambda {|cmd, args|
35
35
  find_user_candidates args, "#{cmd} %s"
36
36
  },
37
37
  :help => ['leave USER', 'Leave user']
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Termtter
3
+ module Client
4
+
5
+ configatron.plugins.grass.set_default(:rate, 0)
6
+
7
+ register_command(
8
+ :name => :w, :aliases => [:grass],
9
+ :exec_proc => lambda {|arg|
10
+ arg, rate = arg.split(/ /)
11
+ count = arg =~ /^[0-9]+$/ ? arg.to_i : 3
12
+ rate ||= configatron.plugins.grass.rate
13
+ grow = (count * rate.to_i).quo(100).round
14
+ grasses = ('w' * (count-grow) + 'W' * grow).split(//).shuffle.join
15
+ call_commands("update #{grasses}")
16
+ },
17
+ :help => ['grass, w', 'Grass it!']
18
+ )
19
+ end
20
+ end
21
+
22
+ # usage
23
+ # > w 10
24
+ # => wwwwwwwwww
25
+ #
26
+ # see also
27
+ # http://d.hatena.ne.jp/tomisima/20090204/1233762301
data/lib/plugin/group.rb CHANGED
@@ -4,7 +4,7 @@ module Termtter
4
4
  class Status
5
5
  def is_member?(group = nil)
6
6
  if group
7
- configatron.plugins.group.groups[:group].include? self.user_screen_name
7
+ configatron.plugins.group.groups[group].include? self.user_screen_name
8
8
  else
9
9
  configatron.plugins.group.groups.values.flatten.include? self.user_screen_name
10
10
  end
@@ -25,10 +25,14 @@ module Termtter::Client
25
25
  register_command(
26
26
  :name => :group,
27
27
  :aliases => [:g],
28
- :exec_proc => proc {|arg|
28
+ :exec_proc => lambda {|arg|
29
29
  unless arg.empty?
30
30
  group_name = arg.to_sym
31
- group = configatron.plugins.group.groups[group_name]
31
+ if group_name == :all
32
+ group = configatron.plugins.group.groups.values.flatten.uniq
33
+ else
34
+ group = configatron.plugins.group.groups[group_name]
35
+ end
32
36
  statuses = group ? public_storage[:log].select { |s|
33
37
  group.include?(s.user_screen_name)
34
38
  } : []
@@ -39,7 +43,7 @@ module Termtter::Client
39
43
  end
40
44
  end
41
45
  },
42
- :completion_proc => proc {|cmd, arg|
46
+ :completion_proc => lambda {|cmd, arg|
43
47
  find_group_candidates arg, "#{cmd} %s"
44
48
  },
45
49
  :help => ['group,g GROUPNAME', 'Filter by group members']
data/lib/plugin/growl.rb CHANGED
@@ -37,7 +37,7 @@ Thread.new do
37
37
  begin
38
38
  if s = queue.pop
39
39
  unless growl
40
- arg = ['growlnotify', s.user_screen_name, '-m', s.text.gsub("\n",''), '-n', 'termtter', '-H', 'localhost']
40
+ arg = ['growlnotify', s.user_screen_name, '-m', s.text.gsub("\n",''), '-n', 'termtter']
41
41
  #icon_path = get_icon_path(s)
42
42
  #arg += ['--image', icon_path] if icon_path
43
43
  system *arg
data/lib/plugin/hatebu.rb CHANGED
@@ -6,7 +6,7 @@ require 'atomutil'
6
6
  module Termtter::Client
7
7
  register_command(
8
8
  :name => :hatebu, :aliases => [],
9
- :exec_proc => proc {|arg|
9
+ :exec_proc => lambda {|arg|
10
10
  if arg =~ /^(\d+)(.*)$/
11
11
  id = $1.strip
12
12
  comment = $2.strip
@@ -41,7 +41,7 @@ module Termtter::Client
41
41
  end
42
42
  end
43
43
  },
44
- :completion_proc => proc {|cmd, args|
44
+ :completion_proc => lambda {|cmd, args|
45
45
  if args =~ /^(\d*)$/
46
46
  find_status_id_candidates $1, "#{cmd} %s"
47
47
  end
@@ -66,6 +66,15 @@ module Termtter::Client
66
66
  save_history
67
67
  end
68
68
  end
69
+
70
+ register_command(
71
+ :name => :save,
72
+ :exec_proc => lambda{|arg|
73
+ save_history
74
+ },
75
+ :help => ['save', 'Save hisory']
76
+ )
77
+
69
78
 
70
79
  end
71
80
 
data/lib/plugin/log.rb CHANGED
@@ -19,7 +19,7 @@ module Termtter::Client
19
19
 
20
20
  register_command(
21
21
  :name => :log,
22
- :exec_proc => proc{|arg|
22
+ :exec_proc => lambda{|arg|
23
23
  if arg.empty?
24
24
  # log
25
25
  statuses = public_storage[:log]
@@ -36,18 +36,26 @@ module Termtter::Client
36
36
  call_hooks(statuses[-print_max..-1], :search)
37
37
  end
38
38
  },
39
- :completion_proc => proc {|cmd, arg|
39
+ :completion_proc => lambda {|cmd, arg|
40
40
  find_user_candidates arg, "#{cmd} %s"
41
41
  },
42
42
  :help => [ 'log (USER(S)) (MAX)', 'Show local log of the user(s)']
43
43
  )
44
44
 
45
- # These are old code we must fix.
46
-
47
- add_help 'log', 'Show local log'
45
+ register_command(
46
+ :name => :search_log, :aliases => [:sl],
47
+ :exec_proc => lambda{|arg|
48
+ unless arg.strip.empty?
49
+ pat = Regexp.new arg
50
+ statuses = public_storage[:log].select { |s| s.text =~ pat }
51
+ call_hooks(statuses, :search)
52
+ end
53
+ },
54
+ :help => [ 'search_log WORD', 'Search log for WORD' ]
55
+ )
48
56
 
49
- add_help '/WORD', 'Search log for WORD'
50
57
  add_command %r'^/(.+)' do |m, t|
58
+ warn '/WORD command will be removed. Use search_log command instead.'
51
59
  pat = Regexp.new(m[1])
52
60
  statuses = public_storage[:log].select { |s| s.text =~ pat }
53
61
  call_hooks(statuses, :search, t)