[pass] [PATCH] Fix pass completion syntax and autoloading

Marc Cornellà marc.cornella at live.com
Sun Jul 20 18:37:38 CEST 2014


Hi, I found a bug in zsh completion and I posted it in oh-my-zsh [1]. Then
I saw your repository and that you prefer pull requests via mailing list,
so I did a format-patch which I post here.
This is the first time I do this, forgive me if I didn't paste the proper
output; I'm pasting all of it just in case.

Cheers,

Marc Cornellà
[1] https://github.com/robbyrussell/oh-my-zsh/pull/2941
----------------------------------------------------------------------------------
>From e250a37fefa4c0bdd3f6591b82b8cc455342826e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20Cornell=C3=A0?= <marc.cornella at live.com>
Date: Sun, 20 Jul 2014 18:22:04 +0200
Subject: [PATCH] Fix pass completion syntax and autoloading

When TAB is pressed, sometimes the following error appears:

  _values:compvalues:10: not enough arguments

>From robbyrussell/oh-my-zsh#2846:

> It seems like this does not happen if I have passwords in pass.
> Only happens when pass is "empty".

This is due to lines 104 and 118, where there are the only `_values'
statements. If we follow the execution path it is also confirmed that
the responsible for that error is `_pass_complete_entries_helper()'.

The only thing left to try is the statement inside `$()', which returns
nothing. The output is blank, so `_values' only receives 1 of its 2
mandatory parameters.

To solve it, we wrap the `$()' argument inside double quotes. That way
even if the output of such command is blank, `_values' still receives
2 of its 2 mandatory parameters, therefore not complaining anymore.

This patch also fixes the first tab completion, which is dedicated to
loading the completion function instead of autoloading it properly.
We do this by adding a `_pass' statement at the end of the file, just
like any other completion file does and *needs* to do.
---
 src/completion/pass.zsh-completion | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/completion/pass.zsh-completion
b/src/completion/pass.zsh-completion
index b658398..f485042 100644
--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -114,7 +114,7 @@ _pass_cmd_show () {
 _pass_complete_entries_helper () {
  local IFS=$'\n'
  local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
- _values -C 'passwords' $(find -L "$prefix" \( -name .git -o -name .gpg-id
\) -prune -o $@ -print | sed -e "s#${prefix}/\{0,1\}##" -e 's#\.gpg##' |
sort)
+ _values -C 'passwords' "$(find -L "$prefix" \( -name .git -o -name
.gpg-id \) -prune -o $@ -print | sed -e "s#${prefix}/\{0,1\}##" -e
's#\.gpg##' | sort)"
 }

 _pass_complete_entries_with_subdirs () {
@@ -128,5 +128,7 @@ _pass_complete_entries () {
 _pass_complete_keys () {
  local IFS=$'\n'
  # Extract names and email addresses from gpg --list-keys
- _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f
10 | sort -u | sed '/^$/d')
+ _values 'gpg keys' "$(gpg2 --list-secret-keys --with-colons | cut -d : -f
10 | sort -u | sed '/^$/d')"
 }
+
+_pass
-- 
2.0.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20140720/233768be/attachment.html>


More information about the Password-Store mailing list