Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Delete and Kill multiple sessions at once #3518

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,29 @@ pub(crate) fn delete_all_sessions(yes: bool, force: bool) {
process::exit(0);
}

pub(crate) fn kill_session(target_session: &Option<String>) {
match target_session {
Some(target_session) => {
assert_session(target_session);
kill_session_impl(target_session);
process::exit(0);
},
None => {
println!("Please specify the session name to kill.");
process::exit(1);
},
pub(crate) fn kill_session(target_sessions: &[String]) {
if target_sessions.len() > 0 {
for session in target_sessions {
assert_session(session);
kill_session_impl(session);
}
process::exit(0);
} else {
println!("Please specify the session name to kill.");
process::exit(1);
}
}

pub(crate) fn delete_session(target_session: &Option<String>, force: bool) {
match target_session {
Some(target_session) => {
assert_dead_session(target_session, force);
delete_session_impl(target_session, force);
process::exit(0);
},
None => {
println!("Please specify the session name to delete.");
process::exit(1);
},
pub(crate) fn delete_session(target_sessions: &[String], force: bool) {
if target_sessions.len() > 0 {
for session in target_sessions {
assert_dead_session(session, force);
delete_session_impl(session, force);
}
process::exit(0);
} else {
println!("Please specify the session name to delete.");
process::exit(1);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ fn main() {
commands::list_aliases(opts);
} else if let Some(Command::Sessions(Sessions::KillAllSessions { yes })) = opts.command {
commands::kill_all_sessions(yes);
} else if let Some(Command::Sessions(Sessions::KillSession { ref target_session })) =
} else if let Some(Command::Sessions(Sessions::KillSession { ref target_sessions })) =
opts.command
{
commands::kill_session(target_session);
commands::kill_session(target_sessions);
} else if let Some(Command::Sessions(Sessions::DeleteAllSessions { yes, force })) = opts.command
{
commands::delete_all_sessions(yes, force);
} else if let Some(Command::Sessions(Sessions::DeleteSession {
ref target_session,
ref target_sessions,
force,
})) = opts.command
{
commands::delete_session(target_session, force);
commands::delete_session(target_sessions, force);
} else if let Some(path) = opts.server {
commands::start_server(path, opts.debug);
} else {
Expand Down
8 changes: 4 additions & 4 deletions zellij-utils/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,17 @@ pub enum Sessions {
/// Kill a specific session
#[clap(visible_alias = "k")]
KillSession {
/// Name of target session
/// Name of target session(s) to kill
#[clap(value_parser)]
target_session: Option<String>,
target_sessions: Vec<String>,
},

/// Delete a specific session
#[clap(visible_alias = "d")]
DeleteSession {
/// Name of target session
/// Name of target session(s) to kill
#[clap(value_parser)]
target_session: Option<String>,
target_sessions: Vec<String>,
/// Kill the session if it's running before deleting it
#[clap(short, long, value_parser, takes_value(false), default_value("false"))]
force: bool,
Expand Down