Merge pull request #1454 from jpttrssn/expand-tilde
fix: Expand tilde in location path
This commit is contained in:
commit
aab6bd95e2
1 changed files with 17 additions and 0 deletions
17
src/tab.rs
17
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<Message>);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue