From b5c17d4743eb05747712b54fcf68bc421ad7ad10 Mon Sep 17 00:00:00 2001 From: Jesse Harwin Date: Thu, 2 Oct 2025 22:26:41 -0700 Subject: [PATCH] completions/bind: bug fixes, cleanup, and complete multiple functions Revamped and renamed the __fish_bind_test2 function. Now has a more explicit name, `__fish_bind_has_keys` and allows for multiple functions after the key-combo, doesn't offer function names after an argument with a parameter (e.g. -M MODE). Logic on the function is now more concise. Closes #11864 --- share/completions/bind.fish | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/share/completions/bind.fish b/share/completions/bind.fish index ac1a68ee6..adf9a4480 100644 --- a/share/completions/bind.fish +++ b/share/completions/bind.fish @@ -1,21 +1,16 @@ -function __fish_bind_test2 - set -l args - for i in (commandline -pxc) - switch $i - case "-*" - - case "*" - set -a args $i - end - end - - switch (count $args) - case 2 - return 0 - end - - return 1 +set -l bind_optspecs \ + a/all \ + e/erase \ + M/mode= \ + m/sets-mode= \ + preset \ + s/silent \ + user +function __fish_bind_has_keys --inherit-variable bind_optspecs + argparse $bind_optspecs -- $argv 2>/dev/null + or return + test (count $argv) -ge 2 end complete -c bind -f @@ -31,11 +26,10 @@ complete -c bind -s s -l silent -d 'Operate silently' complete -c bind -l preset -d 'Operate on preset bindings' complete -c bind -l user -d 'Operate on user bindings' -complete -c bind -n __fish_bind_test2 -a '(bind --function-names)' -d 'Function name' -x +complete -c bind -n '__fish_bind_has_keys (commandline -pcx)' -a '(bind --function-names)' -d 'Function name' -x -function __fish_bind_complete - argparse M/mode= m/sets-mode= preset user s/silent \ - a/all e/erase -- (commandline -xpc)[2..] 2>/dev/null +function __fish_bind_complete --inherit-variable bind_optspecs + argparse $bind_optspecs -- (commandline -xpc)[2..] 2>/dev/null or return 1 set -l token (commandline -ct) if test (count $argv) = 0 && set -l prefix (string match -r -- '(.*,)?(ctrl-|alt-|shift-|super-)*' $token)