talks 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +57 -3
- data/bin/talking +10 -0
- data/bin/talks +3 -0
- data/lib/talks.rb +5 -0
- data/lib/talks/configuration.rb +16 -0
- data/lib/talks/hooks.rb +74 -0
- data/lib/talks/version.rb +1 -1
- metadata +8 -3
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
### Now it works only on MacOS X, soon we'll add support for linux and maybe windows through eSpeak or festival
|
4
4
|
|
5
|
-
### This is beta now
|
5
|
+
### This is beta now. Specs are really needed.
|
6
6
|
|
7
7
|
If you want to HEAR some response from your code, just use this gem.
|
8
8
|
|
@@ -15,6 +15,12 @@ and you want to know when this task will ends, but don't want to check your mac
|
|
15
15
|
you can just add small hook in the end of your code and when it will ends - you will hear it with voice that you
|
16
16
|
choose from MacOS X `say` function collection.
|
17
17
|
|
18
|
+
You can find some examples of `talks` usage in organization [ruby-talks](https://github.com/ruby-talks):
|
19
|
+
|
20
|
+
* [rails-talks](https://github.com/ruby-talks/rails-talks)
|
21
|
+
* [bundler-talks](https://github.com/ruby-talks/bundler-talks)
|
22
|
+
* [spec-talks](https://github.com/ruby-talks/spec-talks)
|
23
|
+
|
18
24
|
## How?
|
19
25
|
|
20
26
|
This gem just using native MacOS X `say` command line tool.
|
@@ -36,6 +42,50 @@ messages:
|
|
36
42
|
The same you can do in your code dynamicly through Talks.config instance.
|
37
43
|
You can configure now only default voice for `say` method and voices and messages for 4 types of talks: `info, warn, success, error`
|
38
44
|
|
45
|
+
For command-line commands you can configure default voices and hook messages:
|
46
|
+
|
47
|
+
`~/.talksrc`
|
48
|
+
```yml
|
49
|
+
bundle:
|
50
|
+
voice: 'vicki'
|
51
|
+
before_message: 'Bundler again will do all right'
|
52
|
+
after_message: "Bundler's job is done here"
|
53
|
+
```
|
54
|
+
|
55
|
+
You can create your own default preferences for each command-line tool which you want to run with `talks` or `talking` command in front:
|
56
|
+
|
57
|
+
`~/.talksrc`
|
58
|
+
```yml
|
59
|
+
ls:
|
60
|
+
voice: 'bad'
|
61
|
+
before_message: 'Now we will see what in the directory'
|
62
|
+
after_message: ''
|
63
|
+
cap:
|
64
|
+
...
|
65
|
+
vim:
|
66
|
+
...
|
67
|
+
scp:
|
68
|
+
...
|
69
|
+
... and etc
|
70
|
+
```
|
71
|
+
|
72
|
+
### Using talks/talking command-line tool
|
73
|
+
|
74
|
+
`talks` or `talking` command-line tool wrap your command-line commands with talks hooks:
|
75
|
+
|
76
|
+
```bash
|
77
|
+
$ talking bundle install
|
78
|
+
```
|
79
|
+
|
80
|
+
After that `talks` will wrap execution of this command with voice messages. By default messages will be like 'command_name task started/ended'.
|
81
|
+
You can preconfigure messages in your `~/.talksrc` file or you can send options right in talking command:
|
82
|
+
|
83
|
+
```bash
|
84
|
+
$ talking -v agnes -bm 'We gonna die!' -am 'Not sure if we can hear that' rm -rf ./
|
85
|
+
# the same
|
86
|
+
$ talking --voice agnes --before-message 'We...' --after-message 'Not...' rm -rf ./
|
87
|
+
```
|
88
|
+
|
39
89
|
### Using talks in your code
|
40
90
|
|
41
91
|
```bash
|
@@ -74,14 +124,18 @@ VOICES = %w(
|
|
74
124
|
|
75
125
|
## Who?
|
76
126
|
|
77
|
-
I did it myself
|
127
|
+
I did it by myself
|
78
128
|
|
79
129
|
### Contributors
|
80
130
|
|
81
|
-
* @gazay
|
131
|
+
* @gazay
|
82
132
|
|
83
133
|
### A lot of thanks
|
84
134
|
|
135
|
+
* @aderyabin - idea of extended customization of talks is his.
|
136
|
+
|
137
|
+
* @brainopia - bro helps me with any my idea. He adviced me to do command line tool talks.
|
138
|
+
|
85
139
|
You can help me with this fun gem and I'll gladly add you here, or above
|
86
140
|
|
87
141
|
## License
|
data/bin/talking
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
talks_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(talks_dir) unless $LOAD_PATH.include?(talks_dir)
|
5
|
+
require 'talks'
|
6
|
+
|
7
|
+
command = (ARGV.first == 'talks' ? ARGV[1..-1] : ARGV)
|
8
|
+
command_with_hooks = Talks.add_hooks command
|
9
|
+
|
10
|
+
exec command_with_hooks
|
data/bin/talks
ADDED
data/lib/talks.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path('../talks/configuration.rb', __FILE__)
|
2
|
+
require File.expand_path('../talks/hooks.rb', __FILE__)
|
2
3
|
|
3
4
|
module Talks
|
4
5
|
class << self
|
@@ -26,6 +27,10 @@ module Talks
|
|
26
27
|
`say -v #{say_voice(type, options)} #{message}`
|
27
28
|
end
|
28
29
|
|
30
|
+
def add_hooks(command)
|
31
|
+
Talks::Hooks.create command
|
32
|
+
end
|
33
|
+
|
29
34
|
TYPES.each do |type|
|
30
35
|
define_method type do |message = nil, options = {type: type}|
|
31
36
|
message ||= config.message(type)
|
data/lib/talks/configuration.rb
CHANGED
@@ -40,6 +40,22 @@ module Talks
|
|
40
40
|
[message(type), voice(type)]
|
41
41
|
end
|
42
42
|
|
43
|
+
def default_message_for(command_name, position = :after)
|
44
|
+
"#{command_name} task #{position == :before ? 'started' : 'ended'}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def message_for(command_name, position = :after)
|
48
|
+
command = command_name.to_sym
|
49
|
+
options[command] &&
|
50
|
+
options[command][(position == :before ? :before_message : :after_message)]
|
51
|
+
end
|
52
|
+
|
53
|
+
def voice_for(command_name)
|
54
|
+
command = command_name.to_sym
|
55
|
+
options[command] &&
|
56
|
+
options[command][:voice]
|
57
|
+
end
|
58
|
+
|
43
59
|
private
|
44
60
|
|
45
61
|
def symbolize_hash_keys(opts)
|
data/lib/talks/hooks.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Talks
|
2
|
+
module Hooks
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def create(args)
|
6
|
+
engine = check_engine
|
7
|
+
options, args = shift_options(args.dup)
|
8
|
+
command_name = command args
|
9
|
+
voice, before_message, after_message = parse options, command_name
|
10
|
+
|
11
|
+
before_hook = hook(engine, voice, before_message)
|
12
|
+
after_hook = hook(engine, voice, after_message)
|
13
|
+
command = args.join(' ')
|
14
|
+
|
15
|
+
[before_hook, command, after_hook].join('; ')
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def shift_options(args, options={})
|
21
|
+
# Check arguments for talks
|
22
|
+
# one-two dashed. -v or --voice
|
23
|
+
if args.first =~ /^-{1,2}[\w-]+$/
|
24
|
+
options[args[0]] = args[1]
|
25
|
+
args.shift(2)
|
26
|
+
shift_options(args, options)
|
27
|
+
else
|
28
|
+
[options, args]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def command(args)
|
33
|
+
if args[0..1] == %w(bundle exec)
|
34
|
+
args[2]
|
35
|
+
else
|
36
|
+
args[0]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_engine
|
41
|
+
if RUBY_PLATFORM =~ /darwin/i
|
42
|
+
'say'
|
43
|
+
else
|
44
|
+
abort 'Now talks can work only on MacOS X, you can help with support other OS'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse(options, command_name)
|
49
|
+
voice = options['-v'] || options['--voice'] ||
|
50
|
+
Talks.config.voice_for(command_name.to_sym) ||
|
51
|
+
Talks.config.default_voice
|
52
|
+
|
53
|
+
before_message = options['-bm'] || options['--before-message'] ||
|
54
|
+
Talks.config.message_for(command_name, :before) ||
|
55
|
+
Talks.config.default_message_for(command_name, :before)
|
56
|
+
|
57
|
+
after_message = options['-am'] || options['--after-message'] ||
|
58
|
+
Talks.config.message_for(command_name, :after) ||
|
59
|
+
Talks.config.default_message_for(command_name, :after)
|
60
|
+
|
61
|
+
[voice, before_message, after_message]
|
62
|
+
end
|
63
|
+
|
64
|
+
def hook(engine, voice, message)
|
65
|
+
if engine == 'say'
|
66
|
+
"say #{message} -v #{voice}"
|
67
|
+
else
|
68
|
+
abort 'Now you can use talks gem only on mac with say'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/talks/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,14 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Simple gem for `say` function of mac os x
|
15
15
|
email:
|
16
16
|
- alex.gaziev@gmail.com
|
17
|
-
executables:
|
17
|
+
executables:
|
18
|
+
- talking
|
19
|
+
- talks
|
18
20
|
extensions: []
|
19
21
|
extra_rdoc_files: []
|
20
22
|
files:
|
@@ -22,8 +24,11 @@ files:
|
|
22
24
|
- Gemfile
|
23
25
|
- README.md
|
24
26
|
- Rakefile
|
27
|
+
- bin/talking
|
28
|
+
- bin/talks
|
25
29
|
- lib/talks.rb
|
26
30
|
- lib/talks/configuration.rb
|
31
|
+
- lib/talks/hooks.rb
|
27
32
|
- lib/talks/runner.rb
|
28
33
|
- lib/talks/version.rb
|
29
34
|
- spec/talks.rb
|