Skip to content

Commit 98fa92a

Browse files
committed
feat(wpmctl): add units cmd to print units dir path
1 parent 27aa497 commit 98fa92a

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

examples/json/komokana.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/LGUG2Z/wpm/refs/heads/master/schema.unit.json",
3+
"Unit": {
4+
"Name": "komokana",
5+
"Description": "Automatic application-aware keyboard layer switching for Windows",
6+
"Requires": [
7+
"komorebi",
8+
"kanata"
9+
]
10+
},
11+
"Service": {
12+
"Kind": "Simple",
13+
"Autostart": true,
14+
"ExecStart": {
15+
"Executable": "komokana.exe",
16+
"Arguments": [
17+
"--kanata-port",
18+
"9999",
19+
"--configuration",
20+
"$USERPROFILE/komokana.yaml",
21+
"--default-layer",
22+
"qwerty"
23+
]
24+
},
25+
"Healthcheck": {
26+
"Process": {
27+
"DelaySec": 1
28+
}
29+
},
30+
"Restart": "OnFailure",
31+
"RestartSec": 2
32+
}
33+
}

examples/toml/komokana.toml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[Unit]
2+
Name = "komokana"
3+
Description = "Automatic application-aware keyboard layer switching for Windows"
4+
Requires = [
5+
"komorebi",
6+
"kanata",
7+
]
8+
9+
[Service]
10+
Kind = "Simple"
11+
Autostart = true
12+
Restart = "OnFailure"
13+
RestartSec = 2
14+
15+
[Service.ExecStart]
16+
Executable = "komokana.exe"
17+
Arguments = [
18+
"--kanata-port",
19+
"9999",
20+
"--configuration",
21+
"$USERPROFILE/komokana.yaml",
22+
"--default-layer",
23+
"qwerty",
24+
]
25+
26+
[Service.Healthcheck.Process]
27+
DelaySec = 1

wpm/src/generators.rs

+33
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,39 @@ impl Definition {
227227
exec_start_post: None,
228228
},
229229
},
230+
Self {
231+
schema: None,
232+
unit: Unit {
233+
name: "komokana".to_string(),
234+
description: Some("Automatic application-aware keyboard layer switching for Windows".to_string()),
235+
requires: Some(vec!["komorebi".to_string(), "kanata".to_string()]),
236+
},
237+
service: Service {
238+
kind: ServiceKind::Simple,
239+
exec_start: ServiceCommand {
240+
executable: Executable::Local(PathBuf::from("komokana.exe")),
241+
arguments: Some(vec![
242+
"--kanata-port".to_string(),
243+
"9999".to_string(),
244+
"--configuration".to_string(),
245+
"$USERPROFILE/komokana.yaml".to_string(),
246+
"--default-layer".to_string(),
247+
"qwerty".to_string()
248+
]),
249+
environment: None,
250+
},
251+
environment: None,
252+
working_directory: None,
253+
healthcheck: Some(Healthcheck::default()),
254+
restart: RestartStrategy::OnFailure,
255+
restart_sec: Some(2),
256+
exec_stop: None,
257+
exec_stop_post: None,
258+
autostart: true,
259+
exec_start_pre: None,
260+
exec_start_post: None,
261+
},
262+
},
230263
Self {
231264
schema: None,
232265
unit: Unit {

wpm/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ pub fn wpm_log_dir() -> PathBuf {
5757
wpm_data_dir().join("logs")
5858
}
5959

60+
pub fn wpm_units_dir() -> PathBuf {
61+
dirs::home_dir()
62+
.expect("could not find home dir")
63+
.join(".config")
64+
.join("wpm")
65+
}
66+
6067
#[derive(Debug, Serialize, Deserialize)]
6168
pub enum SocketMessage {
6269
Start(Vec<String>),

wpmctl/src/main.rs

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use wpm::unit::Definition;
1717
use wpm::unit::Executable;
1818
use wpm::unit::ScoopExecutable;
1919
use wpm::wpm_data_dir;
20+
use wpm::wpm_units_dir;
2021
use wpm::SocketMessage;
2122

2223
#[derive(Parser)]
@@ -89,6 +90,8 @@ enum SubCommand {
8990
Log(Log),
9091
/// Ensure all remote dependencies are downloaded and built
9192
Rebuild,
93+
/// Print the path to the wpm global unit definition directory
94+
Units,
9295
}
9396

9497
fn listen_for_response() -> Result<String, Box<dyn std::error::Error>> {
@@ -198,6 +201,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
198201
}
199202
}
200203
}
204+
SubCommand::Units => {
205+
println!("{}", wpm_units_dir().display());
206+
}
201207
}
202208

203209
Ok(())

0 commit comments

Comments
 (0)