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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 668bbb45792868d5cdc9d9e8ec08e57a0ee0cad7f6b8f6f06d9d0525054c6419
4
- data.tar.gz: 85432c2885378382bce069b276898886bfb6b6b3e90af780d8de303844b793fb
3
+ metadata.gz: 5987ece6a74065567cefd14df9cc39f228669eff6ce33eb0e439c2007087f074
4
+ data.tar.gz: 8c9e8e68b8a5b06e5f561f19d1af725a9cda77af588066fd441b5f6a1ea257c8
5
5
  SHA512:
6
- metadata.gz: c415912e5e87e7f9fed56d1d1a4cbc50573bc57a8ada623b8e950cf852e7eeb08c05285a87491e44bca50919162407c44b19720610891abcbe4cb86c059cef38
7
- data.tar.gz: 4c512102ec35dcf5641771c60cc848e42c1b1dc936312f1a94816f0044346961158ddc51a84b91ad1a551c4021201c2376c1e21e0a4428d07d38d53ec95e1976
6
+ metadata.gz: ece556cbd069a9da7f4fd1c9b530a99cfa94c12d09951ea9ac4bdac46b47a33e4db9e6a3535a9df1f561b538b954337d93135f53763702868e6788edbf7c5389
7
+ data.tar.gz: 840f61d4eeb052f52011129d1e2c64823dcbe78742dd907642e6cb2741254429bdbf87f34e7395bda7563a3d771c60e20afae5e661a53854c3ffc304dbee452e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.0]
4
+
5
+ - Add `awake-for` command to keep the Mac awake for a given duration.
6
+
3
7
  ## [0.8.0]
4
8
 
5
9
  - Replace `ruby-openai` with `ruby_llm` in `q`.
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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "matheus"
6
+
7
+ Matheus::AwakeFor.call ARGV
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Matheus
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.0"
5
5
  end
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.8.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