Commit 14aa97251c

14aa97251c14b2f4db18b611134d1983f2ee2446

parent: 55456dbc1e

Unregistered key

vaw <git@nlih.de> · 2025-10-25 19:52 UTC
committer: <noreply@github.com>

Expand `~` and shell variables in dirs config (#538)

Layout: unified · split

Cargo.lock +10
@@ -2287,6 +2287,7 @@ dependencies = [
22872287 "rpassword",
22882288 "serde",
22892289 "serde_json",
2290 "shellexpand",
22902291 "sled",
22912292 "temp-dir",
22922293 "thiserror 1.0.69",
@@ -5108,6 +5109,15 @@ dependencies = [
51085109 "lazy_static 1.5.0",
51095110]
51105111
5112[[package]]
5113name = "shellexpand"
5114version = "3.1.1"
5115source = "registry+https://github.com/rust-lang/crates.io-index"
5116checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb"
5117dependencies = [
5118 "dirs",
5119]
5120
51115121[[package]]
51125122name = "shlex"
51135123version = "1.3.0"
Cargo.toml +1
@@ -65,6 +65,7 @@ url = {version = "^2.2.2", features = ["serde"]}
6565edit = "0.1.4"
6666humansize = "2.0.0"
6767linkify = "0.10.0"
68shellexpand = "3.1.1"
6869
6970[dependencies.comrak]
7071version = "0.22.0"
src/config.rs +48 −17
@@ -707,11 +707,11 @@ impl DirectoryValues {
707707
708708#[derive(Clone, Default, Deserialize)]
709709pub struct Directories {
710 pub cache: Option<PathBuf>,
711 pub data: Option<PathBuf>,
712 pub logs: Option<PathBuf>,
713 pub downloads: Option<PathBuf>,
714 pub image_previews: Option<PathBuf>,
710 pub cache: Option<String>,
711 pub data: Option<String>,
712 pub logs: Option<String>,
713 pub downloads: Option<String>,
714 pub image_previews: Option<String>,
715715}
716716
717717impl Directories {
@@ -728,6 +728,11 @@ impl Directories {
728728 fn values(self) -> DirectoryValues {
729729 let cache = self
730730 .cache
731 .map(|dir| {
732 let dir = shellexpand::full(&dir)
733 .expect("unable to expand shell variables in dirs.cache");
734 Path::new(dir.as_ref()).to_owned()
735 })
731736 .or_else(|| {
732737 let mut dir = dirs::cache_dir()?;
733738 dir.push("iamb");
@@ -737,6 +742,11 @@ impl Directories {
737742
738743 let data = self
739744 .data
745 .map(|dir| {
746 let dir = shellexpand::full(&dir)
747 .expect("unable to expand shell variables in dirs.cache");
748 Path::new(dir.as_ref()).to_owned()
749 })
740750 .or_else(|| {
741751 let mut dir = dirs::data_dir()?;
742752 dir.push("iamb");
@@ -744,19 +754,40 @@ impl Directories {
744754 })
745755 .expect("no dirs.data value configured!");
746756
747 let logs = self.logs.unwrap_or_else(|| {
748 let mut dir = cache.clone();
749 dir.push("logs");
750 dir
751 });
752
753 let downloads = self.downloads.or_else(dirs::download_dir);
757 let logs = self
758 .logs
759 .map(|dir| {
760 let dir = shellexpand::full(&dir)
761 .expect("unable to expand shell variables in dirs.cache");
762 Path::new(dir.as_ref()).to_owned()
763 })
764 .unwrap_or_else(|| {
765 let mut dir = cache.clone();
766 dir.push("logs");
767 dir
768 });
754769
755 let image_previews = self.image_previews.unwrap_or_else(|| {
756 let mut dir = cache.clone();
757 dir.push("image_preview_downloads");
758 dir
759 });
770 let downloads = self
771 .downloads
772 .map(|dir| {
773 let dir = shellexpand::full(&dir)
774 .expect("unable to expand shell variables in dirs.cache");
775 Path::new(dir.as_ref()).to_owned()
776 })
777 .or_else(dirs::download_dir);
778
779 let image_previews = self
780 .image_previews
781 .map(|dir| {
782 let dir = shellexpand::full(&dir)
783 .expect("unable to expand shell variables in dirs.cache");
784 Path::new(dir.as_ref()).to_owned()
785 })
786 .unwrap_or_else(|| {
787 let mut dir = cache.clone();
788 dir.push("image_preview_downloads");
789 dir
790 });
760791
761792 DirectoryValues { cache, data, logs, downloads, image_previews }
762793 }