diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-05-06 21:38:10 +0200 |
|---|---|---|
| committer | a-kenji <aks.kenji@protonmail.com> | 2021-05-12 19:51:29 +0200 |
| commit | ffd8f17a94e60dc7fffea0a1ef5efccc693c5cd9 (patch) | |
| tree | 62da299a597d95b7ba12272c3df4bc3ec7fc7ecd /src/common/setup.rs | |
| parent | Merge pull request #223 from zellij-org/isolate-pty (diff) | |
| download | sl0ppij-ffd8f17a94e60dc7fffea0a1ef5efccc693c5cd9.tar.gz sl0ppij-ffd8f17a94e60dc7fffea0a1ef5efccc693c5cd9.tar.xz sl0ppij-ffd8f17a94e60dc7fffea0a1ef5efccc693c5cd9.zip | |
Add Complile Time System Directories
closes #380
* --features disable_automatic_asset_installation
disables automatic installation of the `data_dir`
* a set PREFIX env will use `$PREFIX/zellij` as its `data_dir`
Diffstat (limited to 'src/common/setup.rs')
| -rw-r--r-- | src/common/setup.rs | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/common/setup.rs b/src/common/setup.rs index edfa858a..bcda4589 100644 --- a/src/common/setup.rs +++ b/src/common/setup.rs @@ -1,6 +1,8 @@ -use crate::common::utils::consts::{SYSTEM_DEFAULT_CONFIG_DIR, VERSION}; +use crate::common::utils::consts::{ + SYSTEM_DEFAULT_CONFIG_DIR, SYSTEM_DEFAULT_DATA_DIR_PREFIX, VERSION, ZELLIJ_PROJ_DIR, +}; use crate::os_input_output::set_permissions; -use directories_next::{BaseDirs, ProjectDirs}; +use directories_next::BaseDirs; use std::io::Write; use std::{fs, path::Path, path::PathBuf}; @@ -51,6 +53,8 @@ pub mod install { } #[cfg(not(test))] +/// Goes through a predefined list and checks for an already +/// existing config directory, returns the first match pub fn find_default_config_dir() -> Option<PathBuf> { vec![ Some(xdg_config_dir()), @@ -68,9 +72,24 @@ pub fn find_default_config_dir() -> Option<PathBuf> { None } +/// Looks for an existing dir, uses that, else returns a +/// dir matching the config spec. +pub fn get_default_data_dir() -> PathBuf { + vec![ + xdg_data_dir(), + Path::new(SYSTEM_DEFAULT_DATA_DIR_PREFIX).join("share/zellij"), + ] + .into_iter() + .find(|p| p.exists()) + .unwrap_or_else(xdg_data_dir) +} + pub fn xdg_config_dir() -> PathBuf { - let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); - project_dirs.config_dir().to_owned() + ZELLIJ_PROJ_DIR.config_dir().to_owned() +} + +pub fn xdg_data_dir() -> PathBuf { + ZELLIJ_PROJ_DIR.data_dir().to_owned() } pub fn home_config_dir() -> Option<PathBuf> { |
