From 63209cefc2f884ed066d2209cbfa3d3f0efb5e41 Mon Sep 17 00:00:00 2001 From: Slavasil Date: Thu, 19 Mar 2026 18:18:15 +0300 Subject: [PATCH] modify default_config_paths to respect XDG_CONFIG_HOME; remove unnecessary comments; fmt --- src/main.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 820d5b1..9d838bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; const CONFIG_FILENAME: &str = "bot.yml"; const APP_NAME: &str = "deltachat-remotecontrol-bot"; -const APP_DIR: &str = APP_NAME; +const APP_CONFIG_DIR: &str = APP_NAME; /// Delta Chat bot for remote control of local network machines. #[derive(Parser)] @@ -19,21 +19,25 @@ struct Args { config: Option, } -/// Returns the ordered list of default config paths to try when `-c` is not given. -/// The home-directory entry is omitted if $HOME is not set. fn default_config_paths() -> Vec { let mut paths = vec![PathBuf::from(CONFIG_FILENAME)]; - if let Ok(home) = std::env::var("HOME") { + if let Ok(config_home) = std::env::var("XDG_CONFIG_HOME") + .map(|c| PathBuf::from(c)) + .or(std::env::var("HOME").map(|home| PathBuf::from(home).join(".config"))) + { paths.push( - PathBuf::from(home) - .join(".config") - .join(APP_DIR) + PathBuf::from(config_home) + .join(APP_CONFIG_DIR) .join(CONFIG_FILENAME), ); } - paths.push(PathBuf::from("/etc").join(APP_DIR).join(CONFIG_FILENAME)); + paths.push( + PathBuf::from("/etc") + .join(APP_CONFIG_DIR) + .join(CONFIG_FILENAME), + ); paths }