From e46fe04d1c50f893b6c2aa55222792faf16be64c Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Sun, 11 Feb 2024 01:07:41 -0600 Subject: [PATCH] fix completion generators if usage is not installed --- src/cli/completion.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/cli/completion.rs b/src/cli/completion.rs index 21814de62..60762750f 100644 --- a/src/cli/completion.rs +++ b/src/cli/completion.rs @@ -33,17 +33,19 @@ impl Completion { let shell = self.shell.or(self.shell_type).unwrap(); if self.usage || matches!(shell, Shell::Bash | Shell::Fish) { - let shell = shell.to_string(); - cmd!( + let res = cmd!( "usage", "generate", "completion", - &shell, + shell.to_string(), "mise", "--usage-cmd", "mise usage" ) - .run()?; + .run(); + if res.is_err() { + return self.prerendered(shell); + } return Ok(()); } @@ -56,6 +58,16 @@ impl Completion { Ok(()) } + + fn prerendered(&self, shell: Shell) -> Result<()> { + let script = match shell { + Shell::Bash => include_str!("../../completions/mise.bash"), + Shell::Fish => include_str!("../../completions/mise.fish"), + Shell::Zsh => include_str!("../../completions/_mise"), + }; + miseprintln!("{}", script.trim())?; + Ok(()) + } } static AFTER_LONG_HELP: &str = color_print::cstr!( @@ -67,7 +79,7 @@ static AFTER_LONG_HELP: &str = color_print::cstr!( "# ); -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] enum Shell { Bash, Fish,