summaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/consts.rs
diff options
context:
space:
mode:
Diffstat (limited to 'zellij-utils/src/consts.rs')
-rw-r--r--zellij-utils/src/consts.rs66
1 files changed, 39 insertions, 27 deletions
diff --git a/zellij-utils/src/consts.rs b/zellij-utils/src/consts.rs
index 39d125c78..cb11315fc 100644
--- a/zellij-utils/src/consts.rs
+++ b/zellij-utils/src/consts.rs
@@ -1,13 +1,9 @@
//! Zellij program-wide constants.
-use crate::envs;
-use crate::shared::set_permissions;
use directories_next::ProjectDirs;
use lazy_static::lazy_static;
-use nix::unistd::Uid;
use once_cell::sync::OnceCell;
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";
@@ -28,31 +24,8 @@ const fn system_default_data_dir() -> &'static str {
}
lazy_static! {
- static ref UID: Uid = Uid::current();
pub static ref ZELLIJ_PROJ_DIR: ProjectDirs =
ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
- pub static ref ZELLIJ_SOCK_DIR: PathBuf = {
- let mut ipc_dir = envs::get_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);
- ipc_dir
- };
- pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
- let mut sock_dir = ZELLIJ_SOCK_DIR.clone();
- fs::create_dir_all(&sock_dir).unwrap();
- set_permissions(&sock_dir, 0o700).unwrap();
- sock_dir.push(envs::get_session_name().unwrap());
- sock_dir
- };
- pub static ref ZELLIJ_TMP_DIR: PathBuf = PathBuf::from(format!("/tmp/zellij-{}", *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("zellij.log");
pub static ref ZELLIJ_CACHE_DIR: PathBuf = ZELLIJ_PROJ_DIR.cache_dir().to_path_buf();
}
@@ -60,3 +33,42 @@ pub const FEATURES: &[&str] = &[
#[cfg(feature = "disable_automatic_asset_installation")]
"disable_automatic_asset_installation",
];
+
+#[cfg(unix)]
+pub use unix_only::*;
+
+#[cfg(unix)]
+mod unix_only {
+ use super::*;
+ use crate::envs;
+ use crate::shared::set_permissions;
+ use lazy_static::lazy_static;
+ use nix::unistd::Uid;
+ use std::fs;
+
+ lazy_static! {
+ static ref UID: Uid = Uid::current();
+ pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
+ let mut sock_dir = ZELLIJ_SOCK_DIR.clone();
+ fs::create_dir_all(&sock_dir).unwrap();
+ set_permissions(&sock_dir, 0o700).unwrap();
+ sock_dir.push(envs::get_session_name().unwrap());
+ sock_dir
+ };
+ pub static ref ZELLIJ_TMP_DIR: PathBuf = PathBuf::from(format!("/tmp/zellij-{}", *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("zellij.log");
+ pub static ref ZELLIJ_SOCK_DIR: PathBuf = {
+ let mut ipc_dir = envs::get_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);
+ ipc_dir
+ };
+ }
+}