diff options
| author | Kunal Mohan <44079328+kunalmohan@users.noreply.github.com> | 2021-11-30 17:31:05 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-30 17:31:05 +0530 |
| commit | 0ed8f06b9fef7a025bfc1750729350742e227243 (patch) | |
| tree | c83b55a1d740ec02466d80cc47fe5fb208aadf5e | |
| parent | docs(changelog): formatting (diff) | |
| download | sl0ppij-0ed8f06b9fef7a025bfc1750729350742e227243.tar.gz sl0ppij-0ed8f06b9fef7a025bfc1750729350742e227243.tar.xz sl0ppij-0ed8f06b9fef7a025bfc1750729350742e227243.zip | |
Prevent a zellij session from attaching to itself. (#911)
* fix #905
Prevent a zellij session from attaching to itself.
* Add check while attaching using index as well
| -rw-r--r-- | src/commands.rs | 8 | ||||
| -rw-r--r-- | zellij-client/src/lib.rs | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/commands.rs b/src/commands.rs index aec3970e..d1bcb456 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -16,6 +16,7 @@ use zellij_utils::input::options::Options; use zellij_utils::nix; use zellij_utils::{ cli::{CliArgs, Command, SessionCommand, Sessions}, + envs, setup::{get_default_data_dir, Setup}, }; @@ -186,6 +187,13 @@ pub(crate) fn start_client(opts: CliArgs) { attach_with_session_name(session_name, config_options.clone(), create) }; + if let Ok(val) = std::env::var(envs::SESSION_NAME_ENV_KEY) { + if val == *client.get_session_name() { + eprintln!("You are trying to attach to the current session(\"{}\"). Zellij does not support nesting a session in itself", val); + process::exit(1); + } + } + let attach_layout = match client { ClientInfo::Attach(_, _) => None, ClientInfo::New(_) => layout, diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 7633fcdb..f3daf69c 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -91,6 +91,15 @@ pub enum ClientInfo { New(String), } +impl ClientInfo { + pub fn get_session_name(&self) -> &str { + match self { + Self::Attach(ref name, _) => name, + Self::New(ref name) => name, + } + } +} + #[derive(Debug, Clone)] pub(crate) enum InputInstruction { KeyEvent(termion::event::Event, Vec<u8>), |
