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
This commit is contained in:
parent
5180d8016f
commit
0ed8f06b9f
2 changed files with 17 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ use zellij_utils::input::options::Options;
|
||||||
use zellij_utils::nix;
|
use zellij_utils::nix;
|
||||||
use zellij_utils::{
|
use zellij_utils::{
|
||||||
cli::{CliArgs, Command, SessionCommand, Sessions},
|
cli::{CliArgs, Command, SessionCommand, Sessions},
|
||||||
|
envs,
|
||||||
setup::{get_default_data_dir, Setup},
|
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)
|
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 {
|
let attach_layout = match client {
|
||||||
ClientInfo::Attach(_, _) => None,
|
ClientInfo::Attach(_, _) => None,
|
||||||
ClientInfo::New(_) => layout,
|
ClientInfo::New(_) => layout,
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,15 @@ pub enum ClientInfo {
|
||||||
New(String),
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) enum InputInstruction {
|
pub(crate) enum InputInstruction {
|
||||||
KeyEvent(termion::event::Event, Vec<u8>),
|
KeyEvent(termion::event::Event, Vec<u8>),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue