From 1059d878476c231f84ef9d3c2e8bcafaf978bc87 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 13 May 2026 11:27:16 +0200 Subject: Regenerate shell completions and install script fixes - Add hidden completions subcommand to CLI (developer use only) - Regenerate all completion scripts from current CLI structure - Add elvish and powershell completion scripts - install.sh: Fix rsp stop -> rsp stop-daemon, rsp start -> rsp start-daemon - install.sh: Install completions for user's current shell - install.sh: Zsh uses /usr/share/zsh/site-functions/_rsp directly --- src/cli.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'src/cli.rs') diff --git a/src/cli.rs b/src/cli.rs index e0cea63..7d56de6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,7 @@ use crate::config::Config; use crate::database::Database; -use clap::{Parser, Subcommand}; +use clap::{CommandFactory, Parser, Subcommand}; +use clap_complete::{Shell, generate}; use std::path::PathBuf; #[derive(Parser)] @@ -73,6 +74,14 @@ pub enum Commands { #[command(subcommand)] command: SettingsCommands, }, + #[clap(hide = true)] + /// Generate shell completions (developer only) + Completions { + /// Shell to generate (bash, zsh, fish, elvish, powershell) + /// If not specified, generates all completion files + #[arg(value_name = "SHELL")] + shell: Option, + }, } #[derive(Subcommand)] @@ -200,6 +209,38 @@ impl Cli { } } } + Commands::Completions { shell } => { + let mut cmd = Cli::command(); + if let Some(s) = shell { + let shell = match s.as_str() { + "bash" => Shell::Bash, + "zsh" => Shell::Zsh, + "fish" => Shell::Fish, + "elvish" => Shell::Elvish, + "powershell" => Shell::PowerShell, + _ => { + eprintln!("Unknown shell: {s}"); + return Ok(()); + } + }; + generate(shell, &mut cmd, "rsp", &mut std::io::stdout()); + } else { + std::fs::create_dir_all("completions/")?; + let shells = [ + (Shell::Bash, "bash"), + (Shell::Zsh, "zsh"), + (Shell::Fish, "fish"), + (Shell::Elvish, "elvish"), + (Shell::PowerShell, "powershell"), + ]; + for (shell, ext) in &shells { + let path = format!("completions/rsp.{ext}"); + let mut file = std::fs::File::create(&path)?; + generate(*shell, &mut cmd, "rsp", &mut file); + println!("Generated {path}"); + } + } + } } Ok(()) } -- cgit v1.2.3