diff options
author | Daniel Jankowski <Daniel.Jankowski@rub.de> | 2023-10-20 17:51:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-20 17:51:01 +0200 |
commit | 35d93189e3638011883a931a96aea656dd125094 (patch) | |
tree | 7f02e0ea8978c4d69011ac830514e0dd40b377f9 | |
parent | bf41b17cc6e6208447160b259cbfc853d1b9c2cf (diff) |
fix(cli): session names only for attach in fish completion (#2857)
* feat(client): add flag for short output list-sessions
* fix(cli): list session names on fish completion
* chore(client): run cargo fmt
-rw-r--r-- | src/commands.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 8 | ||||
-rw-r--r-- | src/sessions.rs | 13 | ||||
-rw-r--r-- | zellij-utils/assets/completions/comp.fish | 2 | ||||
-rw-r--r-- | zellij-utils/src/cli.rs | 4 |
5 files changed, 26 insertions, 8 deletions
diff --git a/src/commands.rs b/src/commands.rs index 3bc280d34..6074ea7d6 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -206,14 +206,14 @@ pub(crate) fn send_action_to_session( "Session '{}' not found. The following sessions are active:", session_name ); - list_sessions(false); + list_sessions(false, false); std::process::exit(1); } } else if let Ok(session_name) = envs::get_session_name() { attach_with_cli_client(cli_action, &session_name, config); } else { eprintln!("Please specify the session name to send actions to. The following sessions are active:"); - list_sessions(false); + list_sessions(false, false); std::process::exit(1); } }, @@ -355,6 +355,7 @@ fn attach_with_session_name( .map(|s| (s.clone(), Duration::default(), false)) .collect(), false, + false, ); process::exit(1); }, @@ -372,7 +373,7 @@ fn attach_with_session_name( ActiveSession::One(session_name) => ClientInfo::Attach(session_name, config_options), ActiveSession::Many => { println!("Please specify the session to attach to, either by using the full name or a unique prefix.\nThe following sessions are active:"); - list_sessions(false); + list_sessions(false, false); process::exit(1); }, }, diff --git a/src/main.rs b/src/main.rs index a009ba3c6..3d1f37f38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,8 +87,12 @@ fn main() { } } - if let Some(Command::Sessions(Sessions::ListSessions { no_formatting })) = opts.command { - commands::list_sessions(no_formatting); + if let Some(Command::Sessions(Sessions::ListSessions { + no_formatting, + short, + })) = opts.command + { + commands::list_sessions(no_formatting, short); } 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 })) = diff --git a/src/sessions.rs b/src/sessions.rs index d7b326376..c577acc6c 100644 --- a/src/sessions.rs +++ b/src/sessions.rs @@ -146,13 +146,21 @@ fn assert_socket(name: &str) -> bool { } } -pub(crate) fn print_sessions(mut sessions: Vec<(String, Duration, bool)>, no_formatting: bool) { +pub(crate) fn print_sessions( + mut sessions: Vec<(String, Duration, bool)>, + no_formatting: bool, + short: bool, +) { // (session_name, timestamp, is_dead) let curr_session = envs::get_session_name().unwrap_or_else(|_| "".into()); sessions.sort_by(|a, b| a.1.cmp(&b.1)); sessions .iter() .for_each(|(session_name, timestamp, is_dead)| { + if short { + println!("{}", session_name); + return; + } if no_formatting { let suffix = if curr_session == *session_name { format!("(current)") @@ -245,7 +253,7 @@ pub(crate) fn delete_session(name: &str, force: bool) { } } -pub(crate) fn list_sessions(no_formatting: bool) { +pub(crate) fn list_sessions(no_formatting: bool, short: bool) { let exit_code = match get_sessions() { Ok(running_sessions) => { let resurrectable_sessions = get_resurrectable_sessions(); @@ -268,6 +276,7 @@ pub(crate) fn list_sessions(no_formatting: bool) { }) .collect(), no_formatting, + short, ); 0 } diff --git a/zellij-utils/assets/completions/comp.fish b/zellij-utils/assets/completions/comp.fish index a46af36b6..853eda60c 100644 --- a/zellij-utils/assets/completions/comp.fish +++ b/zellij-utils/assets/completions/comp.fish @@ -1,5 +1,5 @@ function __fish_complete_sessions - zellij list-sessions 2>/dev/null + zellij list-sessions --short --no-formatting 2>/dev/null end complete -c zellij -n "__fish_seen_subcommand_from attach" -f -a "(__fish_complete_sessions)" -d "Session" complete -c zellij -n "__fish_seen_subcommand_from a" -f -a "(__fish_complete_sessions)" -d "Session" diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index dd810658d..79aad9947 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -102,6 +102,10 @@ pub enum Sessions { /// Do not add colors and formatting to the list (useful for parsing) #[clap(short, long, value_parser, takes_value(false), default_value("false"))] no_formatting: bool, + + /// Print just the session name + #[clap(short, long, value_parser, takes_value(false), default_value("false"))] + short: bool, }, /// Attach to a session |