diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-22 21:16:44 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-22 22:19:50 +0530 |
| commit | 1162d40ea00aec38907c7079e53c62a02c2c5eda (patch) | |
| tree | d215180e62ea3a7b4d0604f652a65fac7a71b5ac /src/main.rs | |
| parent | join router threads on exit (diff) | |
| download | sl0ppij-1162d40ea00aec38907c7079e53c62a02c2c5eda.tar.gz sl0ppij-1162d40ea00aec38907c7079e53c62a02c2c5eda.tar.xz sl0ppij-1162d40ea00aec38907c7079e53c62a02c2c5eda.zip | |
check if session exists before attaching
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 42 |
1 files changed, 5 insertions, 37 deletions
diff --git a/src/main.rs b/src/main.rs index 319ad307..5a6d5ed1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,15 @@ +mod list_sessions; #[cfg(test)] mod tests; +use list_sessions::{assert_session, list_sessions}; use std::convert::TryFrom; -use std::os::unix::fs::FileTypeExt; -use std::{fs, io, process}; +use std::process; use zellij_client::{os_input_output::get_client_os_input, start_client}; use zellij_server::{os_input_output::get_server_os_input, start_server}; use zellij_utils::{ cli::{CliArgs, Command, Sessions}, - consts::{ZELLIJ_SOCK_DIR, ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, + consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, input::config::Config, logging::*, setup::Setup, @@ -55,6 +56,7 @@ pub fn main() { force, })) = opts.command.clone() { + assert_session(&session_name); start_client( Box::new(os_input), opts, @@ -66,37 +68,3 @@ pub fn main() { } } } - -fn list_sessions() { - match fs::read_dir(&*ZELLIJ_SOCK_DIR) { - Ok(files) => { - let mut is_empty = true; - let session_name = std::env::var("ZELLIJ_SESSION_NAME").unwrap_or_else(|_| "".into()); - files.for_each(|file| { - let file = file.unwrap(); - if file.file_type().unwrap().is_socket() { - let fname = file.file_name().into_string().unwrap(); - let suffix = if session_name == fname { - " (current)" - } else { - "" - }; - println!("{}{}", fname, suffix); - is_empty = false; - } - }); - if is_empty { - println!("No active zellij sessions found."); - } - } - Err(err) => { - if let io::ErrorKind::NotFound = err.kind() { - println!("No active zellij sessions found."); - } else { - eprintln!("Error occured: {}", err); - process::exit(1); - } - } - } - process::exit(0); -} |
