summaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/consts.rs
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-05-16 16:42:50 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-16 21:41:56 +0530
commit2038947a14d32d89da2bdbcaa1381c3015ac9c7a (patch)
tree5a332470e32b380816098594a89d3c3db1f6eb53 /zellij-utils/src/consts.rs
parent28212f54309d09263c6daa1801d49e8b4311be12 (diff)
Big refactor: separate crates for client, server and utilities
Diffstat (limited to 'zellij-utils/src/consts.rs')
-rw-r--r--zellij-utils/src/consts.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/zellij-utils/src/consts.rs b/zellij-utils/src/consts.rs
new file mode 100644
index 000000000..799e29132
--- /dev/null
+++ b/zellij-utils/src/consts.rs
@@ -0,0 +1,54 @@
+//! Zellij program-wide constants.
+
+use crate::shared::set_permissions;
+use directories_next::ProjectDirs;
+use lazy_static::lazy_static;
+use nix::unistd::Uid;
+use std::path::PathBuf;
+use std::{env, fs};
+
+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");
+
+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();
+ pub static ref SESSION_NAME: String = names::Generator::default().next().unwrap();
+ pub static ref ZELLIJ_PROJ_DIR: ProjectDirs =
+ ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
+ pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
+ let mut ipc_dir = env::var("ZELLIJ_SOCKET_DIR").map_or_else(
+ |_| {
+ ZELLIJ_PROJ_DIR
+ .runtime_dir()
+ .map_or_else(|| ZELLIJ_TMP_DIR.clone(), |p| p.to_owned())
+ },
+ PathBuf::from,
+ );
+ ipc_dir.push(VERSION);
+ fs::create_dir_all(&ipc_dir).unwrap();
+ set_permissions(&ipc_dir).unwrap();
+ ipc_dir.push(&*SESSION_NAME);
+ ipc_dir
+ };
+ pub static ref ZELLIJ_TMP_DIR: PathBuf =
+ PathBuf::from("/tmp/zellij-".to_string() + &format!("{}", *UID));
+ pub static ref ZELLIJ_TMP_LOG_DIR: PathBuf = ZELLIJ_TMP_DIR.join("zellij-log");
+ pub static ref ZELLIJ_TMP_LOG_FILE: PathBuf = ZELLIJ_TMP_LOG_DIR.join("log.txt");
+}
+
+pub const FEATURES: &[&str] = &[
+ #[cfg(feature = "disable_automatic_asset_installation")]
+ "disable_automatic_asset_installation",
+];