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
data/ChangeLog ADDED
@@ -0,0 +1,115 @@
1
+ == 1.3.0 2009-07-27
2
+
3
+ Koichiro Ohba (3):
4
+ Added group_filter.
5
+
6
+ Shin-ichiro OGAWA (1):
7
+ Fix retweet command.
8
+
9
+ Tomohiro Nishimura (17):
10
+ add github-issues plugin
11
+ add icomment command to github-issues plugin
12
+ add isearch command to github-issues plugin
13
+ now help command allow you to search specific one
14
+ add functionality of hash tag tracking for sl plugin
15
+ fix Termtter::Client.plug bug
16
+ add pool plugin
17
+ add comment for retweet plugin
18
+ register_command can take command name as symbol
19
+ add trends plugin
20
+ remove configatron method (already 1.2.0)
21
+
22
+ Yasuhiro Matsumoto (1):
23
+ some color was broken on windows.
24
+
25
+ emasaka (33):
26
+ expand-tinyurl.rb: added force_encoding for Ruby 1.9
27
+ expand-tinyurl.rb: added config "skip_users"
28
+ expand-tinyurl.rb: added config "shortters"
29
+ expand-tinyurl.rb: add_filter -> register_hook
30
+ expand-tinyurl.rb: refactored expand_url method
31
+ set permission 0600 when creating config file
32
+ modified regexp of ff.im (plugin/expand-tinyurl.rb)
33
+ moved "t.plug 'auto_reload'" to the end of default config file.
34
+ Defined dummy Encoding::UTF_8 for Ruby 1.8 (expand-tinyurl.rb)
35
+ use multiple URL shortening APIs.
36
+ separated options and texts in nofity-send* plugins
37
+ trap SIGCONT to redraw prompt
38
+
39
+ jugyo (79):
40
+ Fixed modify_arg_for_* hook
41
+ Added a hook point for completion.
42
+ Changed the signature of register_hook
43
+ Updated a sample script
44
+ Added a plugin 'standard_completion'.
45
+ Changed to load a plugin 'standard_completion' as default plugin.
46
+ Changed to use completion of standard_completion.rb
47
+ Implemented easy_reply
48
+ Implemented completion for hashtags.
49
+ Fixed regex for completion of search keywords.
50
+ Implemented a db plugins.
51
+ Fixed bug for associations.
52
+ Added a method 'confirm'.
53
+ Added a command 'db_clear'.
54
+ Changed confirm to call block if given.
55
+ Fixed confirm to call pause and resume.
56
+ Added commands 'do_list' and 'db_execute'
57
+ Removed alias 'l' from command 'db_list'.
58
+ Fixed hook :collect_statuses_for_db
59
+ Fixed a bug devel option is not working.
60
+ Removed setting for config.devel
61
+ Changed to remove dir 'rdoc' when 'rake clean'.
62
+ Fixed 'spec_opts'
63
+ Create a plugin 'defaults' that load deafult plugins.
64
+ Added a task to generate gemspec.
65
+ Fixed completion_proc
66
+ Fixed path of standard plugins.
67
+ Implemented the http sever plugin.
68
+ Changed port configurable
69
+ Changed path for execute command.
70
+ Changed to handle files
71
+ Added favicon.ico
72
+ Created a web client.
73
+ Fixed bugs for ajax
74
+ Modified html
75
+ コマンドの処理を全て TaskManager の invoke_and_wait の中でやるようにした
76
+ Fixed commands plug and plugins.
77
+ Added a option 'show_as_thread' to stdout.
78
+ Added options sticky and priority to plugin growl.
79
+ Applied a patch from Kiwamu Okabe to notify-send3
80
+ Added a command 'twitpic' for upload an image to TwitPic.
81
+ Moved a plug 'devel'.
82
+ Added a default task to Rakefile
83
+ Moved retweet plugin to defaults
84
+ Moved fib plugin to defaults
85
+ Moved exec plugin to defaults
86
+ Added a alias '!' for exec command.
87
+ Renamed alias of exit command 'e' to 'quit'.
88
+ Deleted a disused plugin
89
+ Created a plugin 'command_line'.
90
+ Added a irb command.
91
+ Changed to case sensitive for user name completion.
92
+ Fixed Rakefile. (closed #82)
93
+ Changed to not handle error at TaskManager#invoke_and_wait
94
+ Created the hook point 'prepare_command', and clean the code.
95
+ Changed to use the hook point 'prepare_command' for curry.
96
+ Added completion for curry command.
97
+ Created a new hook point named 'prepare_prompt'.
98
+ Changed to use prepare_prompt for curry, and changed specs as command.
99
+
100
+ ktgy (5):
101
+ Added saykanji.rb
102
+
103
+ ujihisa (13):
104
+ Added -m
105
+ Fixed wrong warning message
106
+ Termtter::Client.plug: Enable to receive array
107
+ Added new plugin 'curry'
108
+
109
+ yoppi (2):
110
+ Added 'whois' command
111
+
112
+ == 0.0.1 2008-12-26
113
+
114
+ * 1 major enhancement:
115
+ * Initial release
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = termtter
2
2
 
3
- http://github.com/jugyo/termtter
3
+ http://termtter.org/
4
4
 
5
5
  == DESCRIPTION:
6
6
 
@@ -34,7 +34,7 @@ Search
34
34
 
35
35
  == REQUIREMENTS:
36
36
 
37
- * json_pure
37
+ * json_pure or json
38
38
  * termcolor
39
39
  * rubytter
40
40
 
@@ -62,26 +62,41 @@ If you would like to use proxy server, add configurations like this:
62
62
  You can to load plugins in this way:
63
63
 
64
64
  Termtter::Client.init do |t|
65
- t.plug 'stdout'
66
- t.plug 'standard_commands'
67
- t.plug 'auto_reload'
65
+ t.plug 'fib'
66
+ t.plug 'growl'
68
67
  end
69
68
 
70
69
  To update the config, just restart your termtter proccess.
71
70
 
72
71
  == FORUM:
73
72
 
74
- http://www.lingr.com/room/termtter
75
-
76
- == DOCUMENT:
77
-
78
- http://wiki.github.com/jugyo/termtter/home (in Japanese)
73
+ http://groups.google.co.jp/group/termtter
79
74
 
80
75
  == TODO:
81
76
 
82
77
  - Enhance the document and spec
83
78
  - Improve the UI(a status view, etc...)
84
79
 
80
+ == ADVANCED USAGE:
81
+
82
+ t.plug 'curry'
83
+
84
+ Your termtter can curry commands.
85
+
86
+ > curry u
87
+ u > hi
88
+ updated => hi
89
+ u > curry @ujm
90
+ u @ujm > hi
91
+ updated => @ujm hi
92
+ u @ujm > uncurry
93
+ >
94
+
95
+ You can also type `<` as curry.
96
+
97
+ > < u
98
+ u >
99
+
85
100
  == LICENSE:
86
101
 
87
102
  (The MIT License)
data/Rakefile CHANGED
@@ -1,27 +1,23 @@
1
1
  $:.unshift File.dirname(__FILE__) + '/lib'
2
+
2
3
  require 'spec/rake/spectask'
3
- desc 'run all specs'
4
- Spec::Rake::SpecTask.new do |t|
5
- t.spec_files = FileList['spec/**/*_spec.rb']
6
- t.spec_opts = ['-c']
7
- end
4
+ require 'rake/clean'
5
+ require 'rake/gempackagetask'
6
+ require 'rake/rdoctask'
7
+ require 'termtter/version'
8
8
 
9
- desc 'Generate gemspec'
10
- task :gemspec do |t|
11
- require 'termtter'
12
- open('termtter.gemspec', "wb" ) do |file|
13
- file << <<-EOS
14
- Gem::Specification.new do |s|
15
- s.name = 'termtter'
16
- s.version = '#{Termtter::VERSION}'
17
- s.summary = "Terminal based Twitter client"
18
- s.description = "Termtter is a terminal based Twitter client"
19
- s.files = %w( #{Dir['lib/**/*.rb', 'lib/**/*.erb'].join(' ')}
20
- #{Dir['spec/**/*.rb'].join(' ')}
21
- #{Dir['test/**/*.rb', 'test/**/*.json'].join(' ')}
22
- README.rdoc
23
- History.txt
24
- Rakefile )
9
+ desc "default task"
10
+ task :default => [:install, :spec]
11
+
12
+ name = 'termtter'
13
+ version = Termtter::VERSION
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = name
17
+ s.version = version
18
+ s.summary = "Terminal based Twitter client."
19
+ s.description = "Termtter is a terminal based Twitter client."
20
+ s.files = %w(Rakefile README.rdoc ChangeLog) + Dir.glob("{lib,spec,test}/**/*")
25
21
  s.executables = ["kill_termtter", "termtter"]
26
22
  s.add_dependency("json_pure", ">= 1.1.3")
27
23
  s.add_dependency("highline", ">= 1.5.0")
@@ -33,23 +29,46 @@ Gem::Specification.new do |s|
33
29
  s.rubyforge_project = 'termtter'
34
30
  s.has_rdoc = true
35
31
  s.rdoc_options = ["--main", "README.rdoc", "--exclude", "spec"]
36
- s.extra_rdoc_files = ["README.rdoc", "History.txt"]
32
+ s.extra_rdoc_files = ["README.rdoc", "ChangeLog"]
37
33
  end
38
- EOS
34
+
35
+ Rake::GemPackageTask.new(spec) do |p|
36
+ p.need_tar = true
37
+ end
38
+
39
+ task :gemspec do
40
+ filename = "#{name}.gemspec"
41
+ open(filename, 'w') do |f|
42
+ f.write spec.to_ruby
39
43
  end
40
- puts "Generate gemspec"
44
+ puts <<-EOS
45
+ Successfully generated gemspec
46
+ Name: #{name}
47
+ Version: #{version}
48
+ File: #{filename}
49
+ EOS
41
50
  end
42
51
 
43
- desc 'Generate gem'
44
- task :gem => :gemspec do |t|
45
- system 'gem', 'build', 'termtter.gemspec'
52
+ task :install => [ :package ] do
53
+ sh %{sudo gem install pkg/#{name}-#{version}.gem}
46
54
  end
47
55
 
48
- namespace :gem do
49
- desc 'Install needed gems'
50
- task :install do
51
- %w[ json_pure highline termcolor rubytter ].each do |gem|
52
- sh "sudo gem install #{gem} -r"
53
- end
54
- end
56
+ task :uninstall => [ :clean ] do
57
+ sh %{sudo gem uninstall #{name}}
58
+ end
59
+
60
+ desc 'run all specs'
61
+ Spec::Rake::SpecTask.new do |t|
62
+ t.spec_files = FileList['spec/**/*_spec.rb']
63
+ t.spec_opts = ['-c']
55
64
  end
65
+
66
+ Rake::RDocTask.new do |t|
67
+ t.rdoc_dir = 'rdoc'
68
+ t.title = "rest-client, fetch RESTful resources effortlessly"
69
+ t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
70
+ t.options << '--charset' << 'utf-8'
71
+ t.rdoc_files.include('README.rdoc', 'lib/**/*.rb')
72
+ end
73
+
74
+ CLEAN.include [ 'pkg', 'rdoc' ]
data/lib/plugins/cool.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Termtter::Client
4
- register_macro(:cool, "update @%s cool.",
5
- :help => ['cool {SCREENNAME}', 'update "@{SCREENNAME} cool."'],
6
- :completion_proc => lambda {|cmd, args|
7
- find_user_candidates args, "#{cmd} %s"
8
- }
4
+ register_macro(:cool, "update %s cool.",
5
+ :help => ['cool {SCREENNAME}', 'update "@{SCREENNAME} cool."']
9
6
  )
10
7
  end
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter::Client
4
+ public_storage[:curry] = ''
5
+
6
+ register_command(
7
+ :name => :curry,
8
+ :alias => :<,
9
+ :exec => lambda {|arg|
10
+ unless arg.empty?
11
+ public_storage[:curry] += arg + ' '
12
+ end
13
+ },
14
+ :completion => lambda {|cmd, arg|
15
+ commands.map{|name, command| command.complement(arg)}.
16
+ flatten.
17
+ compact.
18
+ map{|i| "#{cmd} #{i}"}
19
+ }
20
+ )
21
+
22
+ register_command(
23
+ :name => :uncurry,
24
+ :alias => :>,
25
+ :exec=> lambda {|arg|
26
+ public_storage[:curry] = ''
27
+ }
28
+ )
29
+
30
+ register_hook(
31
+ :name => :apply_curry,
32
+ :point => :prepare_command,
33
+ :exec => lambda {|text|
34
+ /^(curry|<|uncurry|>)/ =~ text ? text : public_storage[:curry] + text
35
+ }
36
+ )
37
+
38
+ register_hook(
39
+ :name => :curry_prompt,
40
+ :point => :prepare_prompt,
41
+ :exec => lambda {|prompt| public_storage[:curry] + prompt }
42
+ )
43
+ end
data/lib/plugins/db.rb ADDED
@@ -0,0 +1,91 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'sequel'
3
+
4
+ config.plugins.db.set_default(:path, Termtter::CONF_DIR + '/termtter.db')
5
+
6
+ DB = Sequel.sqlite(config.plugins.db.path) unless defined? DB
7
+
8
+ unless DB.table_exists?(:statuses)
9
+ DB.create_table :statuses do
10
+ primary_key :id
11
+ Integer :user_id
12
+ String :text
13
+ String :source
14
+ String :created_at
15
+ Integer :in_reply_to_status_id
16
+ Integer :in_reply_to_user_id
17
+ end
18
+ end
19
+
20
+ unless DB.table_exists?(:users)
21
+ DB.create_table :users do
22
+ primary_key :id
23
+ String :screen_name
24
+ end
25
+ end
26
+
27
+ class Status < Sequel::Model(:statuses)
28
+ many_to_one :user
29
+ end
30
+
31
+ class User < Sequel::Model(:users)
32
+ one_to_many :statuses
33
+ end
34
+
35
+ module Termtter
36
+ module Client
37
+ register_hook(:collect_statuses_for_db, :point => :pre_filter) do |statuses, event|
38
+ statuses.each do |s|
39
+
40
+ # Save statuses
41
+ if Status.filter(:id => s.id).empty?
42
+ status = {}
43
+ Status.columns.each do |col|
44
+ status[col] =
45
+ case col
46
+ when :user_id
47
+ s.user.id
48
+ else
49
+ s[col] rescue nil
50
+ end
51
+ end
52
+ Status << status
53
+ end
54
+
55
+ # Save users
56
+ if User.filter(:id => s.user.id).empty?
57
+ user = {}
58
+ User.columns.each do |col|
59
+ user[col] = s.user[col]
60
+ end
61
+ User << user
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ register_command(:db_search, :alias => :ds) do |arg|
68
+ statuses = Status.filter(:text.like("%#{arg}%")).limit(20)
69
+ output(statuses, :db_search)
70
+ end
71
+
72
+ register_command(:db_clear) do |arg|
73
+ if confirm('Are you shure?')
74
+ User.delete
75
+ Status.delete
76
+ end
77
+ end
78
+
79
+ register_command(:db_list) do |arg|
80
+ user_name = normalize_as_user_name(arg)
81
+ statuses = Status.join(:users, :id => :user_id).filter(:users__screen_name => user_name).limit(20)
82
+ output(statuses, :db_search)
83
+ end
84
+
85
+ register_command(:db_execute) do |arg|
86
+ DB.execute(arg).each do |row|
87
+ p row
88
+ end
89
+ end
90
+ end
91
+ end
@@ -4,5 +4,9 @@ module Termtter::Client
4
4
  call_commands('reload')
5
5
  end
6
6
 
7
- call_commands('reload')
7
+ register_hook(
8
+ :name => :auto_reload_init,
9
+ :point => :initialize,
10
+ :exec => lambda { call_commands('reload') }
11
+ )
8
12
  end
@@ -0,0 +1,111 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'singleton'
3
+
4
+ module Termtter
5
+ class CommandLine
6
+ include Singleton
7
+
8
+ class << self
9
+ def start
10
+ instance.start
11
+ end
12
+
13
+ def stop
14
+ instance.stop
15
+ end
16
+ end
17
+
18
+ def start
19
+ start_input_thread
20
+ end
21
+
22
+ def stop
23
+ @input_thread.kill
24
+ end
25
+
26
+ def call(command_text)
27
+ # Example:
28
+ # t.register_hook(:post_all, :point => :prepare_command) do |s|
29
+ # "update #{s}"
30
+ # end
31
+ Client.get_hooks('prepare_command').each {|hook|
32
+ command_text = hook.call(command_text)
33
+ }
34
+ Client.call_commands(command_text)
35
+ end
36
+
37
+ def prompt
38
+ prompt_text = config.prompt
39
+ Client.get_hooks('prepare_prompt').each {|hook|
40
+ prompt_text = hook.call(prompt_text)
41
+ }
42
+ prompt_text
43
+ end
44
+
45
+ private
46
+
47
+ def start_input_thread
48
+ setup_readline()
49
+ trap_setting()
50
+ @input_thread = Thread.new do
51
+ while buf = Readline.readline(ERB.new(prompt).result(Termtter::API.twitter.__send__(:binding)), true)
52
+ Readline::HISTORY.pop if buf.empty?
53
+ begin
54
+ call(buf)
55
+ rescue Exception => e
56
+ Client.handle_error(e)
57
+ end
58
+ end
59
+ end
60
+ @input_thread.join
61
+ end
62
+
63
+ def setup_readline
64
+ if Readline.respond_to?(:basic_word_break_characters=)
65
+ Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
66
+ end
67
+ Readline.completion_proc = lambda {|input|
68
+ begin
69
+ words = []
70
+ words << Client.commands.map {|name, command| command.complement(input) }
71
+ Client.get_hooks(:completion).each do |hook|
72
+ words << hook.call(input) rescue nil
73
+ end
74
+ words.flatten.compact
75
+ rescue Exception => e
76
+ Client.handle_error(e)
77
+ end
78
+ }
79
+ vi_or_emacs = config.editing_mode
80
+ unless vi_or_emacs.empty?
81
+ Readline.__send__("#{vi_or_emacs}_editing_mode")
82
+ end
83
+ end
84
+
85
+ def trap_setting()
86
+ begin
87
+ stty_save = `stty -g`.chomp
88
+ trap("INT") do
89
+ begin
90
+ system "stty", stty_save
91
+ ensure
92
+ Client.call_commands('exit')
93
+ end
94
+ end
95
+ trap("CONT") do
96
+ Readline.refresh_line
97
+ end
98
+ rescue ArgumentError
99
+ rescue Errno::ENOENT
100
+ end
101
+ end
102
+ end
103
+
104
+ Client.register_hook(:initialize_command_line, :point => :launched) do
105
+ CommandLine.start
106
+ end
107
+
108
+ Client.register_hook(:finalize_command_line, :point => :exit) do
109
+ CommandLine.stop
110
+ end
111
+ end
@@ -3,14 +3,9 @@
3
3
  module Termtter::Client
4
4
  register_command(
5
5
  :name => :exec,
6
+ :alias => :'!',
6
7
  :exec_proc => lambda{|arg|
7
- return unless arg
8
- begin
9
- pause
10
- system *arg.split(/\s+/)
11
- ensure
12
- resume
13
- end
8
+ system *arg.split(/\s+/) if arg
14
9
  },
15
10
  :help => ['exec SHELL_COMMAND', 'execute a shell command']
16
11
  )
@@ -15,14 +15,11 @@ module Termtter::Client
15
15
  :name => :fibyou,
16
16
  :exec_proc => lambda {|arg|
17
17
  /(\w+)\s(\d+)/ =~ arg
18
- name = $1
18
+ name = normalize_as_user_name($1)
19
19
  n = $2.to_i
20
20
  text = "@#{name} fib(#{n}) = #{fib n}"
21
21
  Termtter::API.twitter.update(text)
22
22
  puts "=> " << text
23
- },
24
- :completion_proc => lambda {|cmd, arg|
25
- find_user_candidates arg, "#{cmd} %s"
26
23
  }
27
24
  )
28
25
  end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ config.plugins.retweet.set_default(:format, '<%= comment %>RT @<%=s.user.screen_name%>: <%=s.text%>')
4
+
5
+ module Termtter::Client
6
+ def self.post_retweet(s, comment = nil)
7
+ comment += ' ' unless comment.nil?
8
+ text = ERB.new(config.plugins.retweet.format).result(binding)
9
+ Termtter::API.twitter.update(text)
10
+ puts "=> #{text}"
11
+ end
12
+
13
+ register_command(
14
+ :name => :retweet,
15
+ :aliases => [:rt],
16
+ :help => ['retweet,rt (ID|@USER)', 'Post a retweet message'],
17
+ :exec_proc => lambda {|arg|
18
+ arg, comment = arg.split(/\s/, 2)
19
+ if public_storage[:typable_id] && s = typable_id_status(arg)
20
+ post_retweet(s, comment)
21
+ else
22
+ case arg
23
+ when /(\d+)/
24
+ post_retweet(Termtter::API.twitter.show(arg), comment)
25
+ when /@([A-Za-z0-9_]+)/
26
+ user = $1
27
+ statuses = Termtter::API.twitter.user_timeline(user)
28
+ return if statuses.empty?
29
+ post_retweet(statuses[0], comment)
30
+ end
31
+ end
32
+ }
33
+ )
34
+ end