~tsdh/swayr

9e6ed161925e1f45a3f58d6770a47b2f141efe60 — Tassilo Horn 2 months ago d0e3661
tilde-expand directories in icon_dirs
1 files changed, 17 insertions(+), 0 deletions(-)

M src/config.rs
M src/config.rs => src/config.rs +17 -0
@@ 30,6 30,22 @@ pub struct Config {
    layout: Option<Layout>,
}

fn tilde_expand_file_names(file_names: Vec<String>) -> Vec<String> {
    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.")
    }