Expand ~ and shell variables in dirs config (#538)
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -2287,6 +2287,7 @@ dependencies = [
|
|||||||
"rpassword",
|
"rpassword",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"shellexpand",
|
||||||
"sled",
|
"sled",
|
||||||
"temp-dir",
|
"temp-dir",
|
||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
@@ -5108,6 +5109,15 @@ dependencies = [
|
|||||||
"lazy_static 1.5.0",
|
"lazy_static 1.5.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shellexpand"
|
||||||
|
version = "3.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb"
|
||||||
|
dependencies = [
|
||||||
|
"dirs",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ url = {version = "^2.2.2", features = ["serde"]}
|
|||||||
edit = "0.1.4"
|
edit = "0.1.4"
|
||||||
humansize = "2.0.0"
|
humansize = "2.0.0"
|
||||||
linkify = "0.10.0"
|
linkify = "0.10.0"
|
||||||
|
shellexpand = "3.1.1"
|
||||||
|
|
||||||
[dependencies.comrak]
|
[dependencies.comrak]
|
||||||
version = "0.22.0"
|
version = "0.22.0"
|
||||||
|
|||||||
@@ -707,11 +707,11 @@ impl DirectoryValues {
|
|||||||
|
|
||||||
#[derive(Clone, Default, Deserialize)]
|
#[derive(Clone, Default, Deserialize)]
|
||||||
pub struct Directories {
|
pub struct Directories {
|
||||||
pub cache: Option<PathBuf>,
|
pub cache: Option<String>,
|
||||||
pub data: Option<PathBuf>,
|
pub data: Option<String>,
|
||||||
pub logs: Option<PathBuf>,
|
pub logs: Option<String>,
|
||||||
pub downloads: Option<PathBuf>,
|
pub downloads: Option<String>,
|
||||||
pub image_previews: Option<PathBuf>,
|
pub image_previews: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Directories {
|
impl Directories {
|
||||||
@@ -728,6 +728,11 @@ impl Directories {
|
|||||||
fn values(self) -> DirectoryValues {
|
fn values(self) -> DirectoryValues {
|
||||||
let cache = self
|
let cache = self
|
||||||
.cache
|
.cache
|
||||||
|
.map(|dir| {
|
||||||
|
let dir = shellexpand::full(&dir)
|
||||||
|
.expect("unable to expand shell variables in dirs.cache");
|
||||||
|
Path::new(dir.as_ref()).to_owned()
|
||||||
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
let mut dir = dirs::cache_dir()?;
|
let mut dir = dirs::cache_dir()?;
|
||||||
dir.push("iamb");
|
dir.push("iamb");
|
||||||
@@ -737,6 +742,11 @@ impl Directories {
|
|||||||
|
|
||||||
let data = self
|
let data = self
|
||||||
.data
|
.data
|
||||||
|
.map(|dir| {
|
||||||
|
let dir = shellexpand::full(&dir)
|
||||||
|
.expect("unable to expand shell variables in dirs.cache");
|
||||||
|
Path::new(dir.as_ref()).to_owned()
|
||||||
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
let mut dir = dirs::data_dir()?;
|
let mut dir = dirs::data_dir()?;
|
||||||
dir.push("iamb");
|
dir.push("iamb");
|
||||||
@@ -744,19 +754,40 @@ impl Directories {
|
|||||||
})
|
})
|
||||||
.expect("no dirs.data value configured!");
|
.expect("no dirs.data value configured!");
|
||||||
|
|
||||||
let logs = self.logs.unwrap_or_else(|| {
|
let logs = self
|
||||||
let mut dir = cache.clone();
|
.logs
|
||||||
dir.push("logs");
|
.map(|dir| {
|
||||||
dir
|
let dir = shellexpand::full(&dir)
|
||||||
});
|
.expect("unable to expand shell variables in dirs.cache");
|
||||||
|
Path::new(dir.as_ref()).to_owned()
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
let mut dir = cache.clone();
|
||||||
|
dir.push("logs");
|
||||||
|
dir
|
||||||
|
});
|
||||||
|
|
||||||
let downloads = self.downloads.or_else(dirs::download_dir);
|
let downloads = self
|
||||||
|
.downloads
|
||||||
|
.map(|dir| {
|
||||||
|
let dir = shellexpand::full(&dir)
|
||||||
|
.expect("unable to expand shell variables in dirs.cache");
|
||||||
|
Path::new(dir.as_ref()).to_owned()
|
||||||
|
})
|
||||||
|
.or_else(dirs::download_dir);
|
||||||
|
|
||||||
let image_previews = self.image_previews.unwrap_or_else(|| {
|
let image_previews = self
|
||||||
let mut dir = cache.clone();
|
.image_previews
|
||||||
dir.push("image_preview_downloads");
|
.map(|dir| {
|
||||||
dir
|
let dir = shellexpand::full(&dir)
|
||||||
});
|
.expect("unable to expand shell variables in dirs.cache");
|
||||||
|
Path::new(dir.as_ref()).to_owned()
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
let mut dir = cache.clone();
|
||||||
|
dir.push("image_preview_downloads");
|
||||||
|
dir
|
||||||
|
});
|
||||||
|
|
||||||
DirectoryValues { cache, data, logs, downloads, image_previews }
|
DirectoryValues { cache, data, logs, downloads, image_previews }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user