Skip to content

Commit

Permalink
open-session: add shell completions (#136)
Browse files Browse the repository at this point in the history
* open-session: add shell completions

* update dependencies
  • Loading branch information
junglerobba authored Dec 2, 2024
1 parent db71f3b commit 75ef696
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 66 deletions.
105 changes: 49 additions & 56 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 75ef696

Please sign in to comment.