Commit 26523ea 1 parent d896016 commit 26523ea Copy full SHA for 26523ea
File tree 5 files changed +78
-3
lines changed
5 files changed +78
-3
lines changed Original file line number Diff line number Diff line change 7
7
"iconize": [
8
8
{
9
9
"field": "title.label",
10
- "regex": "Movement Yoga"
10
+ "regex": "Movement Yoga",
11
11
"icon": "🪷"
12
12
}
13
13
],
14
- "watch ": {
14
+ "watcher ": {
15
15
"hook": {
16
- "path": "/opt/homebrew/bin/sketchybar"
16
+ "path": "/opt/homebrew/bin/sketchybar",
17
17
"args": ["--trigger", "calendar_changed"]
18
18
}
19
19
}
Original file line number Diff line number Diff line change
1
+ import ArgumentParser
2
+ import EventKit
3
+ import Foundation
4
+
5
+ /// `plan config`
6
+ ///
7
+ /// Show config
8
+ struct ShowConfig : ParsableCommand {
9
+ static var configuration = CommandConfiguration (
10
+ commandName: " config " ,
11
+ abstract: " Show config " ,
12
+ shouldDisplay: false
13
+ )
14
+
15
+ mutating func run( ) {
16
+ let config = Loader . readConfig ( )
17
+ StdOut . print ( " \( String ( describing: config) ) " )
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ struct Config : Codable {
2
+ let iconize : [ Rule ] ?
3
+ let watcher : Watcher ?
4
+ }
5
+
6
+ struct Rule : Codable {
7
+ let field : String
8
+ let regex : String
9
+ let icon : String
10
+ }
11
+
12
+ struct Watcher : Codable {
13
+ let hook : Hook ?
14
+ }
15
+
16
+ struct Hook : Codable {
17
+ let path : String
18
+ let args : [ String ]
19
+ }
Original file line number Diff line number Diff line change
1
+ import Foundation
2
+
3
+ enum Loader {
4
+ private static let appName = " plan "
5
+ private static let defaultConfigHome = FileManager . default
6
+ . homeDirectoryForCurrentUser
7
+ . appendingPathComponent ( " .config " )
8
+ private static let xdgConfigHome = ProcessInfo . processInfo. environment [ " XDG_CONFIG_HOME " ]
9
+ . map { URL ( fileURLWithPath: $0) }
10
+ private static let configHome = xdgConfigHome ?? defaultConfigHome
11
+
12
+ private static let configDir = configHome. appendingPathComponent ( appName)
13
+ private static let configUrl = configDir. appendingPathComponent ( " config.json " )
14
+
15
+ private static func readLocalJSON< T: Codable > ( from path: String , as _: T . Type ) -> T ? {
16
+ let url = URL ( fileURLWithPath: path)
17
+
18
+ do {
19
+ let data = try Data ( contentsOf: url)
20
+ let decoder = JSONDecoder ( )
21
+ return try decoder. decode ( T . self, from: data)
22
+ } catch {
23
+ print ( " Error reading or decoding file at \( path) : \( error) " )
24
+ return nil
25
+ }
26
+ }
27
+
28
+ static func readConfig( ) -> Config ? {
29
+ if let config: Config = readLocalJSON ( from: configUrl. path, as: Config . self) {
30
+ return config
31
+ } else {
32
+ print ( " Failed to read JSON file. " )
33
+ return nil
34
+ }
35
+ }
36
+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ struct Plan: ParsableCommand {
13
13
Add . self,
14
14
Calendars . self,
15
15
Next . self,
16
+ ShowConfig . self,
16
17
Today . self,
17
18
Usage . self,
18
19
Watch . self,
You can’t perform that action at this time.
0 commit comments