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`
This commit is contained in:
parent
d5433f8f89
commit
ffd8f17a94
4 changed files with 40 additions and 10 deletions
|
|
@ -78,3 +78,6 @@ assets = [
|
|||
["assets/completions/zellij.fish", "usr/share/fish/vendor_completions.d/zellij.fish", "644"],
|
||||
["assets/completions/_zellij", "usr/share/zsh/vendor-completions/_zellij", "644"],
|
||||
]
|
||||
|
||||
[features]
|
||||
enable_automatic_asset_installation = []
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,16 @@ pub const ZELLIJ_CONFIG_FILE_ENV: &str = "ZELLIJ_CONFIG_FILE";
|
|||
pub const ZELLIJ_CONFIG_DIR_ENV: &str = "ZELLIJ_CONFIG_DIR";
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
// TODO: ${PREFIX} argument in makefile
|
||||
pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij";
|
||||
pub const SYSTEM_DEFAULT_DATA_DIR_PREFIX: &str = system_default_data_dir();
|
||||
|
||||
const fn system_default_data_dir() -> &'static str {
|
||||
if let Some(data_dir) = std::option_env!("PREFIX") {
|
||||
data_dir
|
||||
} else {
|
||||
&"/usr"
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref UID: Uid = Uid::current();
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ use crate::common::{
|
|||
os_input_output::{set_permissions, ServerOsApi},
|
||||
pty_bus::{PtyBus, PtyInstruction},
|
||||
screen::{Screen, ScreenInstruction},
|
||||
setup::install::populate_data_dir,
|
||||
utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_PROJ_DIR},
|
||||
setup::{get_default_data_dir, install::populate_data_dir},
|
||||
utils::consts::ZELLIJ_IPC_PIPE,
|
||||
wasm_vm::{wasi_read_string, wasi_write_object, zellij_exports, PluginEnv, PluginInstruction},
|
||||
ChannelWithContext, SenderType, SenderWithContext,
|
||||
};
|
||||
|
|
@ -209,9 +209,9 @@ fn init_session(
|
|||
let send_pty_instructions = SenderWithContext::new(SenderType::Sender(send_pty_instructions));
|
||||
|
||||
// Determine and initialize the data directory
|
||||
let data_dir = opts
|
||||
.data_dir
|
||||
.unwrap_or_else(|| ZELLIJ_PROJ_DIR.data_dir().to_path_buf());
|
||||
let data_dir = opts.data_dir.unwrap_or_else(get_default_data_dir);
|
||||
|
||||
#[cfg(enable_automatic_assets_installation)]
|
||||
populate_data_dir(&data_dir);
|
||||
|
||||
// Don't use default layouts in tests, but do everywhere else
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue