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