Skip to content

Commit

Permalink
open-session: add shell completions
Browse files Browse the repository at this point in the history
  • Loading branch information
junglerobba committed Dec 1, 2024
1 parent db71f3b commit b74b0e8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
Result, TmsError,
};
use clap::{Args, Parser, Subcommand};
use clap_complete::{ArgValueCandidates, CompletionCandidate};
use error_stack::ResultExt;
use git2::{build::RepoBuilder, FetchOptions, RemoteCallbacks, Repository};
use ratatui::style::Color;
Expand Down Expand Up @@ -145,6 +146,7 @@ pub struct BookmarkCommand {

#[derive(Debug, Args)]
pub struct OpenSessionCommand {
#[arg(add = ArgValueCandidates::new(open_session_completion_candidates))]
/// Name of the session to open.
session: Box<str>,
}
Expand Down Expand Up @@ -762,6 +764,20 @@ fn open_session_command(args: &OpenSessionCommand, config: Config, tmux: &Tmux)
}
}

fn open_session_completion_candidates() -> Vec<CompletionCandidate> {
Config::new()
.change_context(TmsError::ConfigError)
.and_then(|config| create_sessions(&config))
.map(|sessions| {
sessions
.list()
.iter()
.map(CompletionCandidate::new)
.collect::<Vec<_>>()
})
.unwrap_or_default()
}

pub enum SubCommandGiven {
Yes,
No(Box<Config>),
Expand Down

0 comments on commit b74b0e8

Please sign in to comment.