[PATCH 2/3] fish-completion: any first argument matching "-*" implies "show"

Johannes Altmanninger aclopte at gmail.com
Fri Apr 17 14:39:51 UTC 2026


Test cases:

	fish -c 'complete -C"pass -c1 "'
	fish -c 'complete -C"pass -c2 -"' | grep clip

Bash completions use this logic to determine whether to complete
password names:

	case "${COMP_WORDS[1]}" in
		[...]
		show|-*)

fish completions provide password names if the first argument is "-c",
"--clip" but not if it's something like "-c1" or "--clip=2".

Fix this by matching the logic in Bash completions: assume any command
that starts with a "-" implies "pass show".

Looking at how "cmd_extension_or_show" is invoked, we can see that this
implication does not hold for extensions with a name starting with
"-". But it's probably not a good idea to name extensions like that,
and Bash completions do the same.

Reported-by: Jay Thomas <jay at gfax.ch>

Note that zsh completions use "show|*)" instead of "show|-*)".
In future, we could resolve this inconsistency, either way should
be fine.
---
 src/completion/pass.fish-completion | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/completion/pass.fish-completion b/src/completion/pass.fish-completion
index e035f2c..4b43998 100644
--- a/src/completion/pass.fish-completion
+++ b/src/completion/pass.fish-completion
@@ -17,8 +17,11 @@ end
 
 function __fish_pass_uses_command
     set -l cmd (commandline -opc)
+    if not contains -- -- $argv
+        set --prepend argv --
+    end
     if [ (count $cmd) -gt 1 ]
-        if [ $argv[1] = $cmd[2] ]
+        if string match --quiet $argv $cmd[2]
             return 0
         end
     end
@@ -97,8 +100,9 @@ complete -c $PROG -f -n '__fish_pass_uses_command edit' -a "(__fish_pass_print_e
 
 complete -c $PROG -f -n '__fish_pass_needs_command' -a show -d 'Command: show existing password'
 # When no command is given, `show` is defaulted.
-complete -c $PROG -f -n '__fish_pass_uses_command show || __fish_pass_needs_command' -s c -l clip -d 'Put password in clipboard'
-complete -c $PROG -f -n '__fish_pass_uses_command show || __fish_pass_needs_command || __fish_pass_uses_command -c || __fish_pass_uses_command --clip' -a "(__fish_pass_print_entries)"
+set --local uses_show_command '__fish_pass_uses_command --regex -- "^(?:show|-.*)\$"'
+complete -c $PROG -f -n "$uses_show_command || __fish_pass_needs_command" -s c -l clip -d 'Put password in clipboard'
+complete -c $PROG -f -n "$uses_show_command || __fish_pass_needs_command" -a "(__fish_pass_print_entries)"
 
 complete -c $PROG -f -n '__fish_pass_needs_command' -a git -d 'Command: execute a git command'
 complete -c $PROG -f -n '__fish_pass_uses_command git' -a '(__fish_pass_git_complete)'
-- 
2.54.0.rc2.1.gf65aba1e87



More information about the Password-Store mailing list