From bd5f9babd7cc57ea5467772073bcab39ee40db59 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 8 Aug 2024 21:15:32 +0200 Subject: [PATCH] __fish_seen_subcommand_from: Fix error when there's no second token Regression from 2bfa7db7bce2b5a09249c4bbdc95a7e7a5e4ba48 Can be triggered e.g. with `complete -C"history "`. --- share/functions/__fish_seen_subcommand_from.fish | 2 +- tests/checks/complete.fish | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/share/functions/__fish_seen_subcommand_from.fish b/share/functions/__fish_seen_subcommand_from.fish index fe9203cdf..ccf7e05aa 100644 --- a/share/functions/__fish_seen_subcommand_from.fish +++ b/share/functions/__fish_seen_subcommand_from.fish @@ -6,5 +6,5 @@ function __fish_seen_subcommand_from set -l regex (string escape --style=regex -- (commandline -pxc)[2..] | string join '|') - string match -rq -- '^'$regex'$' $argv + string match -rq -- "^$regex"'$' $argv end diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index 90659c31a..cbdbf7f4d 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -614,3 +614,10 @@ function __fish_describe_command end test (count (complete -C"wh" | string match -rv "\tcommand|^while")) -gt 0 && echo "found" || echo "fail" # CHECK: found + +set -l commands check search show +complete -c testcommand -n "not __fish_seen_subcommand_from $commands" -a 'check\t"Check the frobnicator" search\t"Search for frobs" show\t"Show all frobs"' +complete -C'testcommand ' +# CHECK: check{{\t}}Check the frobnicator +# CHECK: search{{\t}}Search for frobs +# CHECK: show{{\t}}Show all frobs