Implement the minimal list-sessions command
This commit is contained in:
parent
d6fc7b04d1
commit
d231d28d7c
2 changed files with 45 additions and 10 deletions
43
src/main.rs
43
src/main.rs
|
|
@ -2,11 +2,13 @@
|
|||
mod tests;
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::os::unix::fs::FileTypeExt;
|
||||
use std::{fs, io, 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},
|
||||
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
|
||||
cli::{CliArgs, Command, Sessions},
|
||||
consts::{ZELLIJ_SOCK_DIR, ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
|
||||
input::config::Config,
|
||||
logging::*,
|
||||
setup::Setup,
|
||||
|
|
@ -16,7 +18,9 @@ use zellij_utils::{
|
|||
pub fn main() {
|
||||
let opts = CliArgs::from_args();
|
||||
|
||||
if let Some(Command::Setup(ref setup)) = opts.command {
|
||||
if let Some(Command::Sessions(Sessions::ListSessions)) = opts.command {
|
||||
list_sessions();
|
||||
} else if let Some(Command::Setup(ref setup)) = opts.command {
|
||||
Setup::from_cli(setup, &opts).expect("Failed to print to stdout");
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +28,7 @@ pub fn main() {
|
|||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
eprintln!("There was an error in the config file:\n{}", e);
|
||||
std::process::exit(1);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap();
|
||||
|
|
@ -34,7 +38,7 @@ pub fn main() {
|
|||
Ok(server_os_input) => server_os_input,
|
||||
Err(e) => {
|
||||
eprintln!("failed to open terminal:\n{}", e);
|
||||
std::process::exit(1);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
start_server(Box::new(os_input), path);
|
||||
|
|
@ -43,9 +47,36 @@ pub fn main() {
|
|||
Ok(os_input) => os_input,
|
||||
Err(e) => {
|
||||
eprintln!("failed to open terminal:\n{}", e);
|
||||
std::process::exit(1);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
start_client(Box::new(os_input), opts, config);
|
||||
}
|
||||
}
|
||||
|
||||
fn list_sessions() {
|
||||
match fs::read_dir(&*ZELLIJ_SOCK_DIR) {
|
||||
Ok(files) => {
|
||||
let mut is_empty = true;
|
||||
files.for_each(|file| {
|
||||
let file = file.unwrap();
|
||||
if file.file_type().unwrap().is_socket() {
|
||||
println!("{}", file.file_name().into_string().unwrap());
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ lazy_static! {
|
|||
pub static ref SESSION_NAME: String = names::Generator::default().next().unwrap();
|
||||
pub static ref ZELLIJ_PROJ_DIR: ProjectDirs =
|
||||
ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
|
||||
pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
|
||||
pub static ref ZELLIJ_SOCK_DIR: PathBuf = {
|
||||
let mut ipc_dir = env::var("ZELLIJ_SOCKET_DIR").map_or_else(
|
||||
|_| {
|
||||
ZELLIJ_PROJ_DIR
|
||||
|
|
@ -37,11 +37,15 @@ lazy_static! {
|
|||
PathBuf::from,
|
||||
);
|
||||
ipc_dir.push(VERSION);
|
||||
fs::create_dir_all(&ipc_dir).unwrap();
|
||||
set_permissions(&ipc_dir).unwrap();
|
||||
ipc_dir.push(&*SESSION_NAME);
|
||||
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).unwrap();
|
||||
sock_dir.push(&*SESSION_NAME);
|
||||
sock_dir
|
||||
};
|
||||
pub static ref ZELLIJ_TMP_DIR: PathBuf =
|
||||
PathBuf::from("/tmp/zellij-".to_string() + &format!("{}", *UID));
|
||||
pub static ref ZELLIJ_TMP_LOG_DIR: PathBuf = ZELLIJ_TMP_DIR.join("zellij-log");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue