Pi66

pind
Simple Rust hotkey daemon.
git clone https://git.pi66.xyz/pind

← back to log

fix: support add support for user paths in config file.

author: pi66
date: 2025-08-31 23:15
hash: 686ce57352ea658a921918b72f4c644254e5a4f3

Diffstat:

M

src/main.rs
7 +++++++++++++++++-------------
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
diff --git a/src/main.rs b/src/main.rs
index 86d0bcf..58beb9e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,10 +26,11 @@


 use evdev::{AttributeSet, Device, KeyCode, enumerate};
-use std::{env::{var,args},fs::read_to_string, path::PathBuf, process::{exit,Command, Stdio}, sync::{Arc, OnceLock}, thread};
+use std::{env::{var,args},fs::{read_to_string,canonicalize}, path::PathBuf, process::{exit,Command, Stdio}, sync::{Arc, OnceLock}, thread};

 const DELAY  :u64  =  25; // 25ms
-const CONFIG :&str =  "/etc/pind/pindrc";
+const CONFIG :&str =  "/etc/pind/pindrc"; // You can use ~/ for user path
+                                          // like ~/.config/pind/pindrc
 static BINDINGS: OnceLock<Arc<Vec<(AttributeSet<KeyCode>, String)>>> = OnceLock::new();

 fn get_bindings() -> Arc<Vec<(AttributeSet<KeyCode>, String)>>
@@ -138,7 +139,7 @@ fn keyboards() -> Vec<PathBuf>

 fn load_config(config: &str) -> Vec<(AttributeSet<KeyCode>, String)>
 {
-    let content = read_to_string(config)
+    let content = read_to_string(canonicalize(PathBuf::from(config.replace("~",&var("HOME").unwrap_or_default()))).unwrap_or_else(|e|{error("config",&e.to_string())}))
         .unwrap_or_else(|e| error("Config file read failed", &e.to_string()));

     content.lines()