From b6c0e437572f6a0fca94aa9d469c42e6de9e18d6 Mon Sep 17 00:00:00 2001
Message-Id: <b6c0e437572f6a0fca94aa9d469c42e6de9e18d6.1454635746.git.l-m-h@web.de>
In-Reply-To: <c48ff10a23e7343c58f71d7cfd7dd888801020fe.1454635746.git.l-m-h@web.de>
References: <c48ff10a23e7343c58f71d7cfd7dd888801020fe.1454635746.git.l-m-h@web.de>
From: Lucas Hoffmann <l-m-h@web.de>
Date: Thu, 27 Aug 2015 08:50:26 +0200
Subject: [PATCH 4/6] use in completion
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.0"

This is a multi-part message in MIME format.
--------------2.7.0
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
 src/completion/pass.bash-completion |  2 +-
 src/completion/pass.fish-completion | 24 ++++--------------------
 src/completion/pass.zsh-completion  | 11 +++--------
 3 files changed, 8 insertions(+), 29 deletions(-)


--------------2.7.0
Content-Type: text/x-patch; name="0004-use-in-completion.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0004-use-in-completion.patch"

diff --git a/src/completion/pass.bash-completion b/src/completion/pass.bash-completion
index efd4b70..7b2f3bc 100644
--- a/src/completion/pass.bash-completion
+++ b/src/completion/pass.bash-completion
@@ -56,7 +56,7 @@ _pass_complete_folders () {
 _pass_complete_keys () {
 	local IFS=$'\n'
 	# Extract names and email addresses from gpg --list-keys
-	local keys="$(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')"
+	local keys="$(pass script-interface keys)"
 	COMPREPLY+=($(compgen -W "${keys}" -- ${cur}))
 }
 
diff --git a/src/completion/pass.fish-completion b/src/completion/pass.fish-completion
index c32a42c..ecf1d6f 100644
--- a/src/completion/pass.fish-completion
+++ b/src/completion/pass.fish-completion
@@ -6,11 +6,7 @@
 set PROG 'pass'
 
 function __fish_pass_get_prefix
-    set -l prefix "$PASSWORD_STORE_DIR"
-    if [ -z "$prefix" ]
-        set prefix "$HOME/.password-store"
-    end
-    echo "$prefix"
+    pass script-interface prefix
 end
 
 function __fish_pass_needs_command
@@ -31,25 +27,13 @@ function __fish_pass_uses_command
 end
 
 function __fish_pass_print_gpg_keys
-    gpg2 --list-keys | grep uid | sed 's/.*<\(.*\)>/\1/'
+    pass script-interface keys
 end
 function __fish_pass_print_entry_dirs
-    set -l prefix (__fish_pass_get_prefix)
-    set -l dirs
-    eval "set dirs "$prefix"/**/"
-    for dir in $dirs
-        set entry (echo "$dir" | sed "s#$prefix/\(.*\)#\1#")
-        echo "$entry"
-    end
+    pass script-interface dirs
 end
 function __fish_pass_print_entries
-    set -l prefix (__fish_pass_get_prefix)
-    set -l files
-    eval "set files "$prefix"/**.gpg"
-    for file in $files
-        set file (echo "$file" | sed "s#$prefix/\(.*\)\.gpg#\1#")
-        echo "$file"
-    end
+    pass script-interface entries
 end
 function __fish_pass_print_entries_and_dirs
     __fish_pass_print_entry_dirs
diff --git a/src/completion/pass.zsh-completion b/src/completion/pass.zsh-completion
index 9bb3f97..bbc3b94 100644
--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -111,24 +111,19 @@ _pass_cmd_show () {
 		"--clip[put it on the clipboard]"
 	_pass_complete_entries
 }
-_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 2>/dev/null | sed -e "s#${prefix}/\{0,1\}##" -e 's#\.gpg##' | sort):-""}
-}
 
 _pass_complete_entries_with_subdirs () {
-	_pass_complete_entries_helper
+	{ pass script-interface entries; pass script-interface dirs } | sort
 }
 
 _pass_complete_entries () {
-	_pass_complete_entries_helper -type f
+	pass script-interface 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' $(pass script-interface keys)
 }
 
 _pass

--------------2.7.0--


