From fef69a3ec1ec32652db84aa9d7823e3517a22e26 Mon Sep 17 00:00:00 2001 From: Tobin Yehle Date: Sun, 3 May 2020 20:35:53 -0700 Subject: [PATCH] Complete recipe names in fish completion script (#625) --- completions/just.fish | 11 +++++++++++ src/subcommand.rs | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/completions/just.fish b/completions/just.fish index 3983a71..8494228 100644 --- a/completions/just.fish +++ b/completions/just.fish @@ -1,3 +1,14 @@ +function __fish_just_complete_recipes + just --summary 2> /dev/null | tr " " "\n" || echo "" +end + +# don't suggest files right off +complete -c just -n "__fish_is_first_arg" --no-files + +# complete recipes +complete -c just -a '(__fish_just_complete_recipes)' + +# autogenerated completions complete -c just -n "__fish_use_subcommand" -l color -d 'Print colorful output' -r -f -a "auto always never" complete -c just -n "__fish_use_subcommand" -s f -l justfile -d 'Use as justfile.' complete -c just -n "__fish_use_subcommand" -l set -d 'Override with ' diff --git a/src/subcommand.rs b/src/subcommand.rs index ae0f6a7..673d4d2 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -23,6 +23,19 @@ pub(crate) enum Subcommand { Variables, } +const FISH_RECIPE_COMPLETIONS: &str = r#"function __fish_just_complete_recipes + just --summary 2> /dev/null | tr " " "\n" || echo "" +end + +# don't suggest files right off +complete -c just -n "__fish_is_first_arg" --no-files + +# complete recipes +complete -c just -a '(__fish_just_complete_recipes)' + +# autogenerated completions +"#; + const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[ ( r#" _arguments "${_arguments_options[@]}" \"#, @@ -127,6 +140,10 @@ impl Subcommand { } } + if let clap::Shell::Fish = shell { + script.insert_str(0, FISH_RECIPE_COMPLETIONS); + } + println!("{}", script.trim()); Ok(())