jugyo-termtter 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/bin/termtter +20 -8
- data/lib/plugin/completion.rb +58 -0
- data/lib/plugin/english.rb +51 -0
- data/lib/plugin/growl.rb +7 -0
- data/lib/plugin/notify-send.rb +16 -0
- data/lib/plugin/say.rb +22 -0
- data/lib/plugin/standard_commands.rb +69 -0
- data/lib/plugin/stdout.rb +41 -0
- data/lib/plugin/uri-open.rb +39 -0
- data/lib/termtter.rb +12 -1
- metadata +9 -9
data/Rakefile
CHANGED
|
@@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/lib/termtter'
|
|
|
4
4
|
# Generate all the Rake tasks
|
|
5
5
|
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
|
6
6
|
$hoe = Hoe.new('termtter', Termtter::VERSION) do |p|
|
|
7
|
+
p.author = ['ujihisa']
|
|
7
8
|
p.developer('jugyo', 'jugyo.org@gmail.com')
|
|
8
9
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
|
9
10
|
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
data/bin/termtter
CHANGED
|
@@ -12,14 +12,26 @@ conf_file = File.expand_path('~/.termtter')
|
|
|
12
12
|
if File.exist? conf_file
|
|
13
13
|
load conf_file
|
|
14
14
|
else
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
print "your twitter username: "
|
|
16
|
+
username = gets.chomp
|
|
17
|
+
print "your twitter password: "
|
|
18
|
+
password = gets.chomp
|
|
19
|
+
File.open(File.expand_path('~/.termtter'), 'w') {|io|
|
|
20
|
+
plugins = Dir.glob(File.dirname(__FILE__) + "/../lib/plugin/*.rb").map {|f|
|
|
21
|
+
f.match(%r|lib/plugin/(.*?).rb$|)[1]
|
|
22
|
+
}
|
|
23
|
+
plugins -= %w[stdout standard_commands]
|
|
24
|
+
plugins.each do |p|
|
|
25
|
+
io.puts "#plugin '#{p}'"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
io.puts "configatron.user_name = 'USERNAME'"
|
|
29
|
+
io.puts "configatron.password = 'PASSWORD'"
|
|
30
|
+
io.puts
|
|
31
|
+
io.puts "# vim: set filetype=ruby"
|
|
32
|
+
}
|
|
33
|
+
puts "generated: ~/.termtter"
|
|
34
|
+
puts "enjoy!"
|
|
23
35
|
end
|
|
24
36
|
|
|
25
37
|
Termtter::Client.run
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'set'
|
|
2
|
+
|
|
3
|
+
module Termtter::Client
|
|
4
|
+
|
|
5
|
+
public_storage[:users] ||= Set.new
|
|
6
|
+
|
|
7
|
+
add_hook do |statuses, event, t|
|
|
8
|
+
if !statuses.empty?
|
|
9
|
+
case event
|
|
10
|
+
when :update_friends_timeline, :replies, :list_user_timeline
|
|
11
|
+
statuses.each do |s|
|
|
12
|
+
public_storage[:users].add(s.user_screen_name)
|
|
13
|
+
s.text.scan(/@[a-zA-Z_0-9]*/).each do |u| # reply
|
|
14
|
+
public_storage[:users].add(u.gsub("@","")) unless u == "@"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module Termtter
|
|
24
|
+
module InputCompletor
|
|
25
|
+
|
|
26
|
+
Commands = %w[exit help list pause update resume replies search show uri-open]
|
|
27
|
+
|
|
28
|
+
def self.find_candidates(a, b)
|
|
29
|
+
if a.empty?
|
|
30
|
+
Termtter::Client.public_storage[:users].to_a
|
|
31
|
+
else
|
|
32
|
+
Termtter::Client.public_storage[:users].
|
|
33
|
+
grep(/^#{Regexp.quote a}/i).map {|u| b % u }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
CompletionProc = proc {|input|
|
|
38
|
+
case input
|
|
39
|
+
when /^l(ist)? +(.*)/
|
|
40
|
+
find_candidates $2, "list %s"
|
|
41
|
+
when /^(update|u)\s+(.*)@([^\s]*)$/
|
|
42
|
+
find_candidates $3, "#{$1} #{$2}@%s"
|
|
43
|
+
when /^uri-open +(.*)/
|
|
44
|
+
find_candidates $1, "uri-open %s"
|
|
45
|
+
else
|
|
46
|
+
Commands.grep(/^#{Regexp.quote input}/)
|
|
47
|
+
end
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
|
|
54
|
+
Readline.completion_proc = Termtter::InputCompletor::CompletionProc
|
|
55
|
+
|
|
56
|
+
# author: bubbles
|
|
57
|
+
#
|
|
58
|
+
# see also: http://d.hatena.ne.jp/bubbles/20090105/1231145823
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Termtter::Client.clear_hooks # FIXME: not to clear all but to clear just stdout.rb
|
|
2
|
+
|
|
3
|
+
# english? :: String -> Boolean
|
|
4
|
+
def english?(message)
|
|
5
|
+
/[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ message
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# FIXME: The code below is a copy from stdout.rb so it's not DRY. DRY it.
|
|
9
|
+
Termtter::Client.add_hook do |statuses, event|
|
|
10
|
+
colors = %w(0 31 32 33 34 35 36 91 92 93 94 95 96)
|
|
11
|
+
|
|
12
|
+
case event
|
|
13
|
+
when :update_friends_timeline, :list_friends_timeline, :list_user_timeline, :show, :replies
|
|
14
|
+
unless statuses.empty?
|
|
15
|
+
if event == :update_friends_timeline then statuses = statuses.reverse end
|
|
16
|
+
statuses.each do |s|
|
|
17
|
+
text = s.text.gsub("\n", '')
|
|
18
|
+
next unless english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
|
|
19
|
+
color_num = colors[s.user_screen_name.hash % colors.size]
|
|
20
|
+
status = "#{s.user_screen_name}: #{text}"
|
|
21
|
+
if s.in_reply_to_status_id
|
|
22
|
+
status += " (reply to #{s.in_reply_to_status_id})"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
case event
|
|
26
|
+
when :update_friends_timeline, :list_friends_timeline
|
|
27
|
+
time_format = '%H:%M:%S'
|
|
28
|
+
else
|
|
29
|
+
time_format = '%m-%d %H:%d'
|
|
30
|
+
end
|
|
31
|
+
time_str = "(#{s.created_at.strftime(time_format)})"
|
|
32
|
+
|
|
33
|
+
puts "#{color(time_str, 90)} #{color(status, color_num)}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
when :search
|
|
37
|
+
statuses.each do |s|
|
|
38
|
+
text = s.text.gsub("\n", '')
|
|
39
|
+
color_num = colors[s.user_screen_name.hash % colors.size]
|
|
40
|
+
status = "#{s.user_screen_name}: #{text}"
|
|
41
|
+
time_str = "(#{s.created_at.strftime('%m-%d %H:%d')})"
|
|
42
|
+
|
|
43
|
+
puts "#{color(time_str, 90)} #{color(status, color_num)}"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# USAGE:
|
|
49
|
+
# Write the line on the *first line* of your ~/.termtter
|
|
50
|
+
# plugin 'english'
|
|
51
|
+
# (english.rb will destroy plugins which were required before)
|
data/lib/plugin/growl.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Termtter::Client.add_hook do |statuses, event|
|
|
2
|
+
if !statuses.empty? && event == :update_friends_timeline
|
|
3
|
+
max = 10
|
|
4
|
+
|
|
5
|
+
text = statuses.take(max).map {|s|
|
|
6
|
+
status_text = CGI.escapeHTML(s.text)
|
|
7
|
+
status_text.gsub!(%r{https?://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+},'<a href="\0">\0</a>')
|
|
8
|
+
status_text.gsub!("\n", '')
|
|
9
|
+
"<b>#{s.user_screen_name}:</b> <span font=\"9.0\">#{status_text}</span>"
|
|
10
|
+
}.join("\n")
|
|
11
|
+
|
|
12
|
+
text << %Q|\n<a href="http://twitter.com/">more...</a>| if statuses.size > max
|
|
13
|
+
|
|
14
|
+
system 'notify-send', 'Termtter', text, '-t', '60000'
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/plugin/say.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
raise 'say.rb runs only in OSX Leopard' if /darwin9/ !~ RUBY_PLATFORM
|
|
2
|
+
|
|
3
|
+
# say :: String -> String -> IO ()
|
|
4
|
+
def say(who, what)
|
|
5
|
+
voices = %w(Alex Bruce Fred Junior Ralph Agnes Kathy Princess Vicki Victoria Albert Bad\ News Bahh Bells Boing Bubbles Cellos Deranged Good\ News Hysterical Pipe\ Organ Trinoids Whisper Zarvox)
|
|
6
|
+
voice = voices[who.hash % voices.size]
|
|
7
|
+
system 'say', '-v', voice, what
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module Termtter::Client
|
|
11
|
+
add_hook do |statuses, event, t|
|
|
12
|
+
if !statuses.empty? && event == :update_friends_timeline
|
|
13
|
+
statuses.reverse.each do |s|
|
|
14
|
+
text_without_uri = s.text.gsub(%r|https?://[^\s]+|, 'U.R.I.')
|
|
15
|
+
say s.user_screen_name, text_without_uri
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# KNOWN BUG:
|
|
22
|
+
# * exit or <C-c> doen't work quickly.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module Termtter::Client
|
|
2
|
+
|
|
3
|
+
add_command /^(update|u)\s+(.*)/ do |m, t|
|
|
4
|
+
text = m[2]
|
|
5
|
+
unless text.empty?
|
|
6
|
+
t.update_status(text)
|
|
7
|
+
puts "=> #{text}"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
add_command /^(list|l)\s*$/ do |m, t|
|
|
12
|
+
statuses = t.get_friends_timeline()
|
|
13
|
+
call_hooks(statuses, :list_friends_timeline, t)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
add_command /^(list|l)\s+([^\s]+)/ do |m, t|
|
|
17
|
+
statuses = t.get_user_timeline(m[2])
|
|
18
|
+
call_hooks(statuses, :list_user_timeline, t)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
add_command /^(search|s)\s+(.+)/ do |m, t|
|
|
22
|
+
call_hooks(t.search(m[2]), :search, t)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
add_command /^(replies|r)\s*$/ do |m, t|
|
|
26
|
+
call_hooks(t.replies(), :replies, t)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
add_command /^show\s+([^\s]+)/ do |m, t|
|
|
30
|
+
call_hooks(t.show(m[1]), :show, t)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
add_command /^pause\s*$/ do |m, t|
|
|
34
|
+
pause
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
add_command /^resume\s*$/ do |m, t|
|
|
38
|
+
resume
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
add_command /^exit\s*$/ do |m, t|
|
|
42
|
+
exit
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
add_command /^help\s*$/ do |m, t|
|
|
46
|
+
puts <<-EOS
|
|
47
|
+
exit Exit
|
|
48
|
+
help Print this help message
|
|
49
|
+
list,l List the posts in your friends timeline
|
|
50
|
+
list,l USERNAME List the posts in the the given user's timeline
|
|
51
|
+
pause Pause updating
|
|
52
|
+
update,u TEXT Post a new message
|
|
53
|
+
resume Resume updating
|
|
54
|
+
replies,r List the most recent @replies for the authenticating user
|
|
55
|
+
search,s TEXT Search for Twitter
|
|
56
|
+
show ID Show a single status
|
|
57
|
+
EOS
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
add_command /^eval\s+(.*)$/ do |m, t|
|
|
61
|
+
begin
|
|
62
|
+
result = eval(m[1]) unless m[1].empty?
|
|
63
|
+
puts "=> #{result.inspect}"
|
|
64
|
+
rescue SyntaxError => e
|
|
65
|
+
puts e
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
def color(str, num)
|
|
2
|
+
"\e[#{num}m#{str}\e[0m"
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
Termtter::Client.add_hook do |statuses, event|
|
|
6
|
+
colors = %w(0 31 32 33 34 35 36 91 92 93 94 95 96)
|
|
7
|
+
|
|
8
|
+
case event
|
|
9
|
+
when :update_friends_timeline, :list_friends_timeline, :list_user_timeline, :show, :replies
|
|
10
|
+
unless statuses.empty?
|
|
11
|
+
if event == :update_friends_timeline then statuses = statuses.reverse end
|
|
12
|
+
statuses.each do |s|
|
|
13
|
+
text = s.text.gsub("\n", '')
|
|
14
|
+
color_num = colors[s.user_screen_name.hash % colors.size]
|
|
15
|
+
status = "#{s.user_screen_name}: #{text}"
|
|
16
|
+
if s.in_reply_to_status_id
|
|
17
|
+
status += " (reply to #{s.in_reply_to_status_id})"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
case event
|
|
21
|
+
when :update_friends_timeline, :list_friends_timeline
|
|
22
|
+
time_format = '%H:%M:%S'
|
|
23
|
+
else
|
|
24
|
+
time_format = '%m-%d %H:%d'
|
|
25
|
+
end
|
|
26
|
+
time_str = "(#{s.created_at.strftime(time_format)})"
|
|
27
|
+
|
|
28
|
+
puts "#{color(time_str, 90)} #{color(status, color_num)}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
when :search
|
|
32
|
+
statuses.each do |s|
|
|
33
|
+
text = s.text.gsub("\n", '')
|
|
34
|
+
color_num = colors[s.user_screen_name.hash % colors.size]
|
|
35
|
+
status = "#{s.user_screen_name}: #{text}"
|
|
36
|
+
time_str = "(#{s.created_at.strftime('%m-%d %H:%d')})"
|
|
37
|
+
|
|
38
|
+
puts "#{color(time_str, 90)} #{color(status, color_num)}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Termtter::Client
|
|
2
|
+
public_storage[:uris] = []
|
|
3
|
+
|
|
4
|
+
add_hook do |statuses, event, t|
|
|
5
|
+
if !statuses.empty? && event == :update_friends_timeline
|
|
6
|
+
statuses.each do |s|
|
|
7
|
+
public_storage[:uris] += s.text.scan(%r|https?://[^\s]+|)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
add_command /^uri-open\s*$/ do |m, t|
|
|
13
|
+
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
|
|
20
|
+
end
|
|
21
|
+
public_storage[:uris].clear
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
add_command /^uri-open\s+list\s*$/ do |m, t|
|
|
25
|
+
puts public_storage[:uris]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
add_command /^uri-open\s+clear\s*$/ do |m, t|
|
|
29
|
+
public_storage[:uris].clear
|
|
30
|
+
puts "clear uris"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
# ~/.termtter
|
|
34
|
+
# plugin 'uri-open'
|
|
35
|
+
#
|
|
36
|
+
# see also: http://ujihisa.nowa.jp/entry/c3dd00c4e0
|
|
37
|
+
#
|
|
38
|
+
# KNOWN BUG
|
|
39
|
+
# * In Debian, exit or C-c in the termtter kills your firefox.
|
data/lib/termtter.rb
CHANGED
|
@@ -16,8 +16,19 @@ def plugin(s)
|
|
|
16
16
|
require "plugin/#{s}"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
# FIXME: delete this method after the major version up
|
|
20
|
+
alias original_require require
|
|
21
|
+
def require(s)
|
|
22
|
+
if %r|^termtter/(.*)| =~ s
|
|
23
|
+
puts "[WARNING] use plugin '#{$1}' instead of require"
|
|
24
|
+
original_require "plugin/#{$1}"
|
|
25
|
+
else
|
|
26
|
+
original_require s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
19
30
|
module Termtter
|
|
20
|
-
VERSION = '0.5.
|
|
31
|
+
VERSION = '0.5.5'
|
|
21
32
|
|
|
22
33
|
class Twitter
|
|
23
34
|
|
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.
|
|
4
|
+
version: 0.5.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- jugyo
|
|
@@ -62,14 +62,14 @@ files:
|
|
|
62
62
|
- example_dot_termtter
|
|
63
63
|
- bin/termtter
|
|
64
64
|
- lib/termtter.rb
|
|
65
|
-
- lib/
|
|
66
|
-
- lib/
|
|
67
|
-
- lib/
|
|
68
|
-
- lib/
|
|
69
|
-
- lib/
|
|
70
|
-
- lib/
|
|
71
|
-
- lib/
|
|
72
|
-
- lib/
|
|
65
|
+
- lib/plugin/stdout.rb
|
|
66
|
+
- lib/plugin/notify-send.rb
|
|
67
|
+
- lib/plugin/standard_commands.rb
|
|
68
|
+
- lib/plugin/uri-open.rb
|
|
69
|
+
- lib/plugin/growl.rb
|
|
70
|
+
- lib/plugin/say.rb
|
|
71
|
+
- lib/plugin/english.rb
|
|
72
|
+
- lib/plugin/completion.rb
|
|
73
73
|
- test/test_termtter.rb
|
|
74
74
|
- test/friends_timeline.json
|
|
75
75
|
- test/search.json
|