From 4782f36b9c66f888af6265815b53eeedf148f090 Mon Sep 17 00:00:00 2001 From: Jonatan Pettersson Date: Fri, 19 Dec 2025 09:54:51 +0100 Subject: [PATCH] fix: Expand tilde in location path --- src/tab.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/tab.rs b/src/tab.rs index d8ad922..4f1c67f 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1489,6 +1489,7 @@ impl Location { } pub fn with_path(&self, path: PathBuf) -> Self { + let path = Self::expand_tilde(path); match self { Self::Desktop(_, display, desktop_config) => { Self::Desktop(path, display.clone(), *desktop_config) @@ -1562,6 +1563,22 @@ impl Location { Self::Network(display_name, ..) => display_name.clone(), } } + + /// Expand a path that starts with "~" with the + /// user's home directory + pub fn expand_tilde(path: PathBuf) -> PathBuf { + let mut components = path.components(); + match components.next() { + Some(std::path::Component::Normal(os_str)) if os_str == "~" => { + if let Some(home) = dirs::home_dir() { + home.join(components.as_path()) + } else { + path + } + } + _ => path, + } + } } pub struct TaskWrapper(pub cosmic::Task);