matheus 0.8.0 → 0.9.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +9 -0
- data/exe/awake-for +7 -0
- data/lib/matheus/awake_for.rb +38 -0
- data/lib/matheus/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5987ece6a74065567cefd14df9cc39f228669eff6ce33eb0e439c2007087f074
|
|
4
|
+
data.tar.gz: 8c9e8e68b8a5b06e5f561f19d1af725a9cda77af588066fd441b5f6a1ea257c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ece556cbd069a9da7f4fd1c9b530a99cfa94c12d09951ea9ac4bdac46b47a33e4db9e6a3535a9df1f561b538b954337d93135f53763702868e6788edbf7c5389
|
|
7
|
+
data.tar.gz: 840f61d4eeb052f52011129d1e2c64823dcbe78742dd907642e6cb2741254429bdbf87f34e7395bda7563a3d771c60e20afae5e661a53854c3ffc304dbee452e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -15,6 +15,15 @@ $ alert-me 'sleep 1 && echo "Done!"'
|
|
|
15
15
|
Done!
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
### [`awake-for`](./lib/matheus/awake_for.rb)
|
|
19
|
+
|
|
20
|
+
Keeps the Mac awake for the given duration, using `caffeinate`.
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
$ awake-for 1h30m
|
|
24
|
+
Staying awake until 15:30. Press Ctrl-C to stop.
|
|
25
|
+
```
|
|
26
|
+
|
|
18
27
|
### [`convert-currency`](./lib/matheus/convert_currency.rb)
|
|
19
28
|
|
|
20
29
|
```sh
|
data/exe/awake-for
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Matheus
|
|
4
|
+
# Usage:
|
|
5
|
+
# $ awake-for 4h
|
|
6
|
+
# $ awake-for 30min
|
|
7
|
+
# $ awake-for 1h30m
|
|
8
|
+
# Keeps the Mac awake for the given duration, using `caffeinate`.
|
|
9
|
+
class AwakeFor < Command
|
|
10
|
+
class Duration < Data.define(:seconds)
|
|
11
|
+
UNITS = {
|
|
12
|
+
"h" => 3600, "hr" => 3600, "hrs" => 3600, "hour" => 3600, "hours" => 3600,
|
|
13
|
+
"m" => 60, "min" => 60, "mins" => 60, "minute" => 60, "minutes" => 60,
|
|
14
|
+
"s" => 1, "sec" => 1, "secs" => 1, "second" => 1, "seconds" => 1
|
|
15
|
+
}.freeze
|
|
16
|
+
PART = /(\d+(?:\.\d+)?)\s*(#{Regexp.union(UNITS.keys.sort_by { -_1.size })})/
|
|
17
|
+
FORMAT = /\A(?:#{PART})+\z/
|
|
18
|
+
|
|
19
|
+
def self.parse(input)
|
|
20
|
+
input = input.downcase.delete(" ")
|
|
21
|
+
return unless input.match?(FORMAT)
|
|
22
|
+
|
|
23
|
+
seconds = input.scan(PART).sum { |amount, unit| UNITS.fetch(unit) * amount.to_f }
|
|
24
|
+
new(seconds.round) if seconds.positive?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def from_now = Time.now + seconds
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def call(args)
|
|
31
|
+
input = args.join(" ")
|
|
32
|
+
duration = Duration.parse(input) or return Failure("invalid duration: #{input.inspect}. Try something like 4h, 30min or 1h30m.")
|
|
33
|
+
|
|
34
|
+
puts "Staying awake until #{duration.from_now.strftime("%H:%M")}. Press Ctrl-C to stop."
|
|
35
|
+
exec("caffeinate", "-dims", "-t", duration.seconds.to_s)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/matheus/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: matheus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matheus Richard
|
|
@@ -112,6 +112,7 @@ email:
|
|
|
112
112
|
- matheusrichardt@gmail.com
|
|
113
113
|
executables:
|
|
114
114
|
- alert-me
|
|
115
|
+
- awake-for
|
|
115
116
|
- convert-currency
|
|
116
117
|
- date-of-last
|
|
117
118
|
- puts
|
|
@@ -129,6 +130,7 @@ files:
|
|
|
129
130
|
- README.md
|
|
130
131
|
- Rakefile
|
|
131
132
|
- exe/alert-me
|
|
133
|
+
- exe/awake-for
|
|
132
134
|
- exe/convert-currency
|
|
133
135
|
- exe/date-of-last
|
|
134
136
|
- exe/puts
|
|
@@ -137,6 +139,7 @@ files:
|
|
|
137
139
|
- exe/quick-commit
|
|
138
140
|
- lib/matheus.rb
|
|
139
141
|
- lib/matheus/alert_me.rb
|
|
142
|
+
- lib/matheus/awake_for.rb
|
|
140
143
|
- lib/matheus/command.rb
|
|
141
144
|
- lib/matheus/convert_currency.rb
|
|
142
145
|
- lib/matheus/date_of_last.rb
|