aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/utils
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-05-03 17:23:32 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-04 20:48:17 +0530
commitea552d71e4b1d4a72d30f4481079cb0e30b0fc58 (patch)
treed557367d1b170e0ce517dc8effd1175783cb6fd1 /src/common/utils
parentuse better names for senders, receivers and threads (diff)
downloadsl0ppij-ea552d71e4b1d4a72d30f4481079cb0e30b0fc58.tar.gz
sl0ppij-ea552d71e4b1d4a72d30f4481079cb0e30b0fc58.tar.xz
sl0ppij-ea552d71e4b1d4a72d30f4481079cb0e30b0fc58.zip
Introduce IpcReceiverWIthContext and move ipc stuff to common/ipc.rs
Fall back to /tmp/zellij-{uid} directory if runtime_dir is not available. Use serialize_into() to avoid Vec allocation. And some cleanup
Diffstat (limited to 'src/common/utils')
-rw-r--r--src/common/utils/consts.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/common/utils/consts.rs b/src/common/utils/consts.rs
index f031dd38..c21e3029 100644
--- a/src/common/utils/consts.rs
+++ b/src/common/utils/consts.rs
@@ -1,5 +1,25 @@
//! Zellij program-wide constants.
+use directories_next::ProjectDirs;
+use lazy_static::lazy_static;
+use nix::unistd::Uid;
+use std::path::PathBuf;
+
pub const ZELLIJ_TMP_DIR: &str = "/tmp/zellij";
pub const ZELLIJ_TMP_LOG_DIR: &str = "/tmp/zellij/zellij-log";
pub const ZELLIJ_TMP_LOG_FILE: &str = "/tmp/zellij/zellij-log/log.txt";
+
+lazy_static! {
+ static ref UID: Uid = Uid::current();
+ pub static ref SESSION_NAME: String = names::Generator::default().next().unwrap();
+ pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
+ let project_dir = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
+ let mut ipc_dir = project_dir
+ .runtime_dir()
+ .map(|p| p.to_owned())
+ .unwrap_or_else(|| PathBuf::from("/tmp/zellij-".to_string() + &format!("{}", *UID)));
+ std::fs::create_dir_all(&ipc_dir).unwrap();
+ ipc_dir.push(&*SESSION_NAME);
+ ipc_dir
+ };
+}