From 404666e11403f73da3c5dcc24e9b62497d13e1c8 Mon Sep 17 00:00:00 2001 From: Sylvain Pasche Date: Sat, 13 Dec 2025 01:12:58 +0100 Subject: [PATCH] Fish completion for global justfile The new approach to build the list of recipes filters the current command line to keep only the options that specify the justfile location (such as `-g` or `-f`). The regex should also fix #2686. --- completions/just.fish | 9 +++++---- src/completions.rs | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/completions/just.fish b/completions/just.fish index f1202115b6..88c20d89fe 100644 --- a/completions/just.fish +++ b/completions/just.fish @@ -1,8 +1,9 @@ function __fish_just_complete_recipes - if string match -rq '(-f|--justfile)\s*=?(?[^\s]+)' -- (string split -- ' -- ' (commandline -pc))[1] - set -fx JUST_JUSTFILE "$justfile" - end - printf "%s\n" (string split " " (just --summary)) + set -l commandline (string split -- ' -- ' (commandline -pc))[1] + set -l justfile_path_args_regex '\s(?:-g|--global-justfile|(?:-f|--justfile)\s*=?[^\s]+)' + set -l filtered_commandline (string match -r $justfile_path_args_regex -- $commandline) + + printf "%s\n" (string split " " (just (string split -n -- ' ' $filtered_commandline) --summary)) end # don't suggest files right off diff --git a/src/completions.rs b/src/completions.rs index 97eda5b4c1..0dd6822b17 100644 --- a/src/completions.rs +++ b/src/completions.rs @@ -101,10 +101,11 @@ mod tests { } const FISH_RECIPE_COMPLETIONS: &str = r#"function __fish_just_complete_recipes - if string match -rq '(-f|--justfile)\s*=?(?[^\s]+)' -- (string split -- ' -- ' (commandline -pc))[1] - set -fx JUST_JUSTFILE "$justfile" - end - printf "%s\n" (string split " " (just --summary)) + set -l commandline (string split -- ' -- ' (commandline -pc))[1] + set -l justfile_path_args_regex '\s(?:-g|--global-justfile|(?:-f|--justfile)\s*=?[^\s]+)' + set -l filtered_commandline (string match -r $justfile_path_args_regex -- $commandline) + + printf "%s\n" (string split " " (just (string split -n -- ' ' $filtered_commandline) --summary)) end # don't suggest files right off