lmkwyd 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.gitlab-ci.yml +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/lmkwyd +5 -0
- data/lib/lmkwyd.rb +11 -0
- data/lib/lmkwyd/commander.rb +59 -0
- data/lib/lmkwyd/notifier.rb +30 -0
- data/lib/lmkwyd/version.rb +3 -0
- data/lmkwyd.gemspec +25 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb5fa8d94865eb470f6231ed7ecca314b19d3ad9
|
4
|
+
data.tar.gz: 650ef50d9d53bea871d9c2538a585254692a9838
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61e6390105bfaf2b4d1aa39dc3016f92b69abbf02eacd63da2cb4db193a98bb977fb07e203799b6cfb5f5d46818a569ecce8b6cf50fccfc45533d2d209161a90
|
7
|
+
data.tar.gz: 1d78598cea3f179fe5eee5aea456a177c37f051836aff7ca8cb17ea7db2aa08e91fcb8af550d40f0576293a90df5956dea603a62180a364a2f4bbda01d3803a2
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Tatsuya Suzuki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# lmkwyd
|
2
|
+
|
3
|
+
Mac terminal command to notify when a specified commands is done by displaying a banner of Notification Center
|
4
|
+
|
5
|
+
### General Usage:
|
6
|
+
|
7
|
+
```shell
|
8
|
+
lmkwyd sleep 3
|
9
|
+
# => displays notification with title "Command Completed", subtitle "sleep 3" and body saying "Time to execute: 00:00:03"
|
10
|
+
```
|
11
|
+
|
12
|
+
![](https://gitlab.com/szkmp/lmkwyd/uploads/65793e28551695b4fd16348db0bd41ea/Screen_Shot_2016-05-08_at_4.40.41_PM.png)
|
13
|
+
|
14
|
+
|
15
|
+
lmkwyd doesn't change exit code of commands a user specified. When
|
16
|
+
consecutive commands are specified lmkwyd exits with exit code of their
|
17
|
+
final result.
|
18
|
+
|
19
|
+
### Usage (variation):
|
20
|
+
|
21
|
+
```shell
|
22
|
+
lmkwyd 'sleep 1 && echo Hey!'
|
23
|
+
# => Sleeps 1 sec and displays notification saying "Hey!"
|
24
|
+
|
25
|
+
lmkwyd 'ls /inexistent && echo Hey!'
|
26
|
+
# => Displays notification and prints stdout 'ls: /inexistent: No such file or directory'
|
27
|
+
# => echo Hey! is not executed, as same result as `lmkwyd ls /inexistent && echo Hey!` (without single quot)
|
28
|
+
|
29
|
+
lmkwyd 'echo Hey! && sleep 10'
|
30
|
+
# => Displays notification 10 seconds after both spcified commands are completed
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Add this line to your application's Gemfile:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'lmkwyd'
|
40
|
+
```
|
41
|
+
|
42
|
+
And then execute:
|
43
|
+
|
44
|
+
$ bundle
|
45
|
+
|
46
|
+
Or install it yourself as:
|
47
|
+
|
48
|
+
$ gem install lmkwyd
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
TODO: Write usage instructions here
|
53
|
+
|
54
|
+
## Development
|
55
|
+
|
56
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
|
+
|
58
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at `https://gitlab.com/szkmp/lmkwyd`.
|
63
|
+
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
68
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lmkwyd"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/lmkwyd
ADDED
data/lib/lmkwyd.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'lmkwyd/notifier'
|
3
|
+
|
4
|
+
# Executes user specified command line
|
5
|
+
#
|
6
|
+
# @example General usage
|
7
|
+
# lmkwyd sleep 3
|
8
|
+
# # => displays notification with title "Command Completed", subtitle "sleep 3" and body saying "Time to execute: 00:00:03"
|
9
|
+
# # => ![](https://gitlab.com/szkmp/lmkwyd/uploads/65793e28551695b4fd16348db0bd41ea/Screen_Shot_2016-05-08_at_4.40.41_PM.png)
|
10
|
+
class Lmkwyd::Commander
|
11
|
+
EXIT_CODE_OK = 0
|
12
|
+
|
13
|
+
attr_reader :command, :duration
|
14
|
+
|
15
|
+
def initialize(command_string)
|
16
|
+
@command = command_string
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes user specified command line
|
20
|
+
#
|
21
|
+
# @return [integer] Exit code of user specified command line
|
22
|
+
# @note This returns exit code 1 (General Error) if one of multiple commands in the command line fails
|
23
|
+
# @example Execute multiple commands
|
24
|
+
# lmkwyd 'sleep 1 && echo Hey!'
|
25
|
+
# # => Sleeps 1 sec and displays notification saying "Hey!"
|
26
|
+
#
|
27
|
+
# lmkwyd 'ls /inexistent && echo Hey!'
|
28
|
+
# # => Displays notification and prints stdout 'ls: /inexistent: No such file or directory'
|
29
|
+
# # => echo Hey! is not executed, as same result as `lmkwyd ls /inexistent && echo Hey!` (without single quot)
|
30
|
+
#
|
31
|
+
# lmkwyd 'echo Hey! && sleep 10'
|
32
|
+
# # => Displays notification 10 seconds after both spcified commands are completed
|
33
|
+
def exec
|
34
|
+
exit_code = EXIT_CODE_OK
|
35
|
+
|
36
|
+
# TODO Check system ruby version
|
37
|
+
@duration = measure_time_consumption {
|
38
|
+
exit_code = run_command
|
39
|
+
}
|
40
|
+
|
41
|
+
exit_code
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def run_command
|
47
|
+
Open3.popen3(command) {|stdin, stdout, stderr, wait_thr|
|
48
|
+
stdout.each {|line| print line }
|
49
|
+
stderr.each {|line| print line }
|
50
|
+
wait_thr.value.exitstatus
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def measure_time_consumption
|
55
|
+
start = Time.now
|
56
|
+
yield
|
57
|
+
Time.now - start
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Lmkwyd::Notifier
|
2
|
+
attr_reader :commander
|
3
|
+
|
4
|
+
def initialize(commander)
|
5
|
+
@commander = commander
|
6
|
+
end
|
7
|
+
|
8
|
+
def notify
|
9
|
+
`#{command}`
|
10
|
+
end
|
11
|
+
|
12
|
+
def command
|
13
|
+
%Q|osascript -e \
|
14
|
+
'display notification "#{body}" \
|
15
|
+
with title "Command completed" \
|
16
|
+
subtitle "#{commander.command}" \
|
17
|
+
sound name "Hero"'|
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def body
|
23
|
+
# TODO make this Linux compatible
|
24
|
+
"Time to execute: #{humanize_length_of_time(commander.duration)}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def humanize_length_of_time(seconds)
|
28
|
+
Time.at(seconds).utc.strftime("%H:%M:%S")
|
29
|
+
end
|
30
|
+
end
|
data/lmkwyd.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lmkwyd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lmkwyd"
|
8
|
+
spec.version = Lmkwyd::VERSION
|
9
|
+
spec.authors = ["Tatsuya Suzuki"]
|
10
|
+
spec.email = ["sin.wave808@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Mac terminal command to notify when a specified command is done by displaying a banner of Notification Center}
|
13
|
+
spec.description = %q{Mac terminal command to notify when a specified command is done by displaying a banner of Notification Center}
|
14
|
+
spec.homepage = "https://gitlab.com/szkmp/lmkwyd"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lmkwyd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tatsuya Suzuki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Mac terminal command to notify when a specified command is done by displaying
|
56
|
+
a banner of Notification Center
|
57
|
+
email:
|
58
|
+
- sin.wave808@gmail.com
|
59
|
+
executables:
|
60
|
+
- lmkwyd
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".gitlab-ci.yml"
|
66
|
+
- ".rspec"
|
67
|
+
- ".travis.yml"
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- exe/lmkwyd
|
75
|
+
- lib/lmkwyd.rb
|
76
|
+
- lib/lmkwyd/commander.rb
|
77
|
+
- lib/lmkwyd/notifier.rb
|
78
|
+
- lib/lmkwyd/version.rb
|
79
|
+
- lmkwyd.gemspec
|
80
|
+
homepage: https://gitlab.com/szkmp/lmkwyd
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.6.4
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Mac terminal command to notify when a specified command is done by displaying
|
104
|
+
a banner of Notification Center
|
105
|
+
test_files: []
|