Quoting Lucas Hoffmann (2016-02-05 21:42:29)
> This even results in a small "bug":  pass assumes that password files
> have a gpg extension.  Other files are not used by `pass show`.  That
> is the internal assumtion/restriction/interface.  The bug is that
> files without a gpg extension are listed in the tree (plain `pass
> show`) but can (obviously) not be shown directly (`pass show makefile`
> says "Error: makefile is not in the password store." even though
> "makefile" is returned by the completion and listed in the tree).

Attached is a patch that fixes some parts of the bug.  Patch 1 and 3
take care that only *.gpg files are considered when showing, finding or
completing password entries.

Patch 2 extends a assumption that is implicit in the sed command that
removes the gpg extension after tree.  Namely that this gpg extension is
lower case.  The patch makes grep and reencrypt only care about files
with lower case gpg extensions.

Patch 4 makes the zsh completion ignore all hidden (.*) files when
completing password entries.  This might be useful for people having a
.gitattributes file to view human readable diffs.  Or people who have a
.bin folder in the password store to keep some scripts hidden from `pass
show` and friends.

Each of these patches can be merged individually, they are not
interdependent (although 1 and 3 are fixing the same bug).
From b49dcc13832e7e84c2ce2aba0bb69a76378dd544 Mon Sep 17 00:00:00 2001
Message-Id: <b49dcc13832e7e84c2ce2aba0bb69a76378dd544.1455008444.git.l-...@web.de>
From: Lucas Hoffmann <[email protected]>
Date: Tue, 9 Feb 2016 09:43:08 +0100
Subject: [PATCH 1/4] show/find: Only list *.gpg files.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.1"

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

---
 src/password-store.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


--------------2.7.1
Content-Type: text/x-patch; name="0001-show-find-Only-list-.gpg-files.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-show-find-Only-list-.gpg-files.patch"

diff --git a/src/password-store.sh b/src/password-store.sh
index 63be840..0dfe0e1 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -324,7 +324,7 @@ cmd_show() {
 		else
 			echo "${path%\/}"
 		fi
-		tree -C -l --noreport "$PREFIX/$path" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
+		tree -C -l --noreport -P '*.gpg' "$PREFIX/$path" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
 	elif [[ -z $path ]]; then
 		die "Error: password store is empty. Try \"pass init\"."
 	else
@@ -335,7 +335,7 @@ cmd_show() {
 cmd_find() {
 	[[ -z "$@" ]] && die "Usage: $PROGRAM $COMMAND pass-names..."
 	IFS="," eval 'echo "Search Terms: $*"'
-	local terms="*$(printf '%s*|*' "$@")"
+	local terms="*$(printf '%s*.gpg|*' "$@")"
 	tree -C -l --noreport -P "${terms%|*}" --prune --matchdirs --ignore-case "$PREFIX" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
 }
 

--------------2.7.1--


From 3b88e1a5b14f342cf7f50d58664f01b42752614b Mon Sep 17 00:00:00 2001
Message-Id: <3b88e1a5b14f342cf7f50d58664f01b42752614b.1455008444.git.l-...@web.de>
In-Reply-To: <b49dcc13832e7e84c2ce2aba0bb69a76378dd544.1455008444.git.l-...@web.de>
References: <b49dcc13832e7e84c2ce2aba0bb69a76378dd544.1455008444.git.l-...@web.de>
From: Lucas Hoffmann <[email protected]>
Date: Tue, 9 Feb 2016 09:48:34 +0100
Subject: [PATCH 2/4] grep/reencrypt: Do not ignore case, only find *.gpg.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.1"

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

---
 src/password-store.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


--------------2.7.1
Content-Type: text/x-patch; name="0002-grep-reencrypt-Do-not-ignore-case-only-find-.gpg.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0002-grep-reencrypt-Do-not-ignore-case-only-find-.gpg.patch"

diff --git a/src/password-store.sh b/src/password-store.sh
index 0dfe0e1..aba181d 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -111,7 +111,7 @@ reencrypt_path() {
 			mv "$passfile_temp" "$passfile" || rm -f "$passfile_temp"
 		fi
 		prev_gpg_recipients="${GPG_RECIPIENTS[*]}"
-	done < <(find "$1" -iname '*.gpg' -print0)
+	done < <(find "$1" -name '*.gpg' -print0)
 }
 check_sneaky_paths() {
 	local path
@@ -352,7 +352,7 @@ cmd_grep() {
 		passfile="${passfile##*/}"
 		printf "\e[94m%s\e[1m%s\e[0m:\n" "$passfile_dir" "$passfile"
 		echo "$grepresults"
-	done < <(find -L "$PREFIX" -iname '*.gpg' -print0)
+	done < <(find -L "$PREFIX" -name '*.gpg' -print0)
 }
 
 cmd_insert() {

--------------2.7.1--


From be25d71d4ce8708231aeced3af6e123bf1fc1686 Mon Sep 17 00:00:00 2001
Message-Id: <be25d71d4ce8708231aeced3af6e123bf1fc1686.1455008444.git.l-...@web.de>
In-Reply-To: <b49dcc13832e7e84c2ce2aba0bb69a76378dd544.1455008444.git.l-...@web.de>
References: <b49dcc13832e7e84c2ce2aba0bb69a76378dd544.1455008444.git.l-...@web.de>
From: Lucas Hoffmann <[email protected]>
Date: Tue, 9 Feb 2016 09:59:25 +0100
Subject: [PATCH 3/4] zsh completion: Only complete *.gpg files for passwords.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.1"

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

---
 src/completion/pass.zsh-completion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


--------------2.7.1
Content-Type: text/x-patch; name="0003-zsh-completion-Only-complete-.gpg-files-for-password.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0003-zsh-completion-Only-complete-.gpg-files-for-password.patch"

diff --git a/src/completion/pass.zsh-completion b/src/completion/pass.zsh-completion
index 27ce15a..cd2a427 100644
--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -132,7 +132,7 @@ _pass_complete_entries_with_subdirs () {
 }
 
 _pass_complete_entries () {
-	_pass_complete_entries_helper -type f
+	_pass_complete_entries_helper -type f -name '*.gpg'
 }
 
 _pass_complete_keys () {

--------------2.7.1--


From 87800239e9a4605c21d7b96ee206569b1c0dc0cc Mon Sep 17 00:00:00 2001
Message-Id: <87800239e9a4605c21d7b96ee206569b1c0dc0cc.1455008444.git.l-...@web.de>
In-Reply-To: <b49dcc13832e7e84c2ce2aba0bb69a76378dd544.1455008444.git.l-...@web.de>
References: <b49dcc13832e7e84c2ce2aba0bb69a76378dd544.1455008444.git.l-...@web.de>
From: Lucas Hoffmann <[email protected]>
Date: Tue, 9 Feb 2016 09:59:44 +0100
Subject: [PATCH 4/4] zsh completion: Ignore all hidden files.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.1"

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


This will also ignore .gitattributes and other files with a dot when
completing entries.
---
 src/completion/pass.zsh-completion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


--------------2.7.1
Content-Type: text/x-patch; name="0004-zsh-completion-Ignore-all-hidden-files.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0004-zsh-completion-Ignore-all-hidden-files.patch"

diff --git a/src/completion/pass.zsh-completion b/src/completion/pass.zsh-completion
index cd2a427..2e6eadc 100644
--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -124,7 +124,7 @@ _pass_complete_entries_helper () {
 	local IFS=$'\n'
 	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#\\#\\\\#' | sort):-""}
+	_values -C 'passwords' ${$(find -L "$prefix" \( -name '.*' \) -prune -o $@ -print 2>/dev/null | sed -e "s#${prefix}/\{0,1\}##" -e 's#\.gpg##' -e 's#\\#\\\\#' | sort):-""}
 }
 
 _pass_complete_entries_with_subdirs () {

--------------2.7.1--


Attachment: signature.asc
Description: signature

_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to