From 9e6ed161925e1f45a3f58d6770a47b2f141efe60 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Thu, 15 Jul 2021 10:34:22 +0200 Subject: [PATCH] tilde-expand directories in icon_dirs --- src/config.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/config.rs b/src/config.rs index de7d04b..33bdcaa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -30,6 +30,22 @@ pub struct Config { layout: Option, } +fn tilde_expand_file_names(file_names: Vec) -> Vec { + let mut ret = vec![]; + for file_name in file_names { + if file_name.starts_with('~') { + ret.push(file_name.replacen( + "~", + &std::env::var("HOME").expect("$HOME not defined"), + 1, + )); + } else { + ret.push(file_name) + } + } + ret +} + impl Config { pub fn get_menu_executable(&self) -> String { self.menu @@ -92,6 +108,7 @@ impl Config { .as_ref() .and_then(|f| f.icon_dirs.clone()) .or_else(|| Format::default().icon_dirs) + .map(tilde_expand_file_names) .expect("No format.icon_dirs defined.") }