[PATCH] Use native zsh functions to handle completion

tuna tunaflish.ai at gmail.com
Sun Mar 15 23:58:30 UTC 2026


Hi all,

I would like to suggest using the zsh's native _files function in the
completion script. This eliminates the dependency on find, sed, and
sort, although they are present on virtually every system. A more
important advantage of using _files is the integration with the zsh
completer, which enables the use cases like `pass p/c/f` -> `pass
parent/child/file`, and `pass <TAB>` will only list one depth of
directories instead of listing all files and their full paths. This is
how completion works for `ls`, and, I think, should be an expected
behavior.
Here is a small example. Expected:
```
% path # <TAB>
dir1/
dir2/
```
Reality:
```
% path # <TAB>
dir1/file1
dir1/file2
dir2/file3
dir2/file4
```
Using _files solves it. It also handles all the special characters, so
`sed` is not needed.

Another completion logic, that I think should be handled by zsh
built-ins instead of hard-coded functionality, is the git subcommand.
A simple `local service=git; _git` will enable ALL git completions,
instead of the subset given in the completion script.

Best regards,
tunaflsh


--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -73,16 +73,8 @@
  _pass_complete_entries_with_subdirs
  ;;
  git)
- local -a subcommands
- subcommands=(
- "init:Initialize git repository"
- "push:Push to remote repository"
- "pull:Pull from remote repository"
- "config:Show git config"
- "log:Show git log"
- "reflog:Show git reflog"
- )
- _describe -t commands 'pass git' subcommands
+ local service=git
+ _git
  ;;
  show|*)
  _pass_cmd_show
@@ -121,10 +113,12 @@
  _pass_complete_entries
 }
 _pass_complete_entries_helper () {
- local IFS=$'\n'
+ local -a ignored=(.git .gpg-id)
  local prefix
  zstyle -s ":completion:${curcontext}:" prefix prefix ||
prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
- _values -C 'passwords' ${$(find -L "$prefix" \( -name .git -o -name
.gpg-id \) -prune -o $@ -print 2>/dev/null | sed -e
"s#${prefix}/\{0,1\}##" -e 's#\.gpg##' -e 's#\\#\\\\#g' -e 's#:#\\:#g'
| sort):-""}
+ # Remove the default all-files fallback
+ zstyle ":completion:${curcontext}:*" file-patterns
'%p:globbed-files' '*(-/):directories'
+ _files -W "$prefix" -g '**.gpg(:r)' -F ignored
 }

 _pass_complete_entries_with_subdirs () {


More information about the Password-Store mailing list