[PATCH] Adding command match - list matching passwords and as if print
Michal Klempa
michal.klempa at gmail.com
Tue Apr 14 18:20:07 CEST 2020
Hello,
I was wondering if command searching through passwords in store and immediately
asking whether to print desired password would be useful. Tried a little and
I came with small code as a draft for discussion and proposal.
The idea is to provide
pass match .com
which would ask for each password matching (just like in find/search), whether
to print.
Example output:
Search Terms: .com
Business/some-silly-business-site.com [y/N]:
Email/donenfeld.com [y/N]: y
sup3rh4x3rizmynam3
Email/zx2c4.com [y/N]: n
works with current dependencies (find, tree, sh). Based on grep code.
I am aware that complete fix would probably require to do some adjustments:
- clip and qrencode for matching password
- testing on other platforms
- de-duplication of code
So take this as a start for discussion, if something like this would find
its users, we can together work out, how to provide also clip/qrencode without
duplicating the code.
Best regards,
Michal
---
man/pass.1 | 22 ++++++++++++++++++++++
src/password-store.sh | 23 +++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/man/pass.1 b/man/pass.1
index a555dcb..cda6acc 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -94,6 +94,11 @@ List names of passwords inside the tree that match \fIpass-names\fP by using the
.BR tree (1)
program. This command is alternatively named \fBsearch\fP.
.TP
+\fBmatch\fP \fIpass-names\fP...
+Like in \fBfind\fP goes through names of passwords inside the tree that match \fIpass-names\fP by using the
+.BR find (1)
+program. For each matched password, user is asked whether to decrypt and print the password.
+.TP
\fBshow\fP [ \fI--clip\fP[=\fIline-number\fP], \fI-c\fP[\fIline-number\fP] ] [ \fI--qrcode\fP[=\fIline-number\fP], \fI-q\fP[\fIline-number\fP] ] \fIpass-name\fP
Decrypt and print a password named \fIpass-name\fP. If \fI--clip\fP or \fI-c\fP
is specified, do not print the password but instead copy the first (or otherwise specified)
@@ -238,6 +243,23 @@ Search Terms: .com
.br
Alternatively, "\fBpass search .com\fP".
.TP
+Loop through all passwords matching .com in store and ask if they should be printed
+.B zx2c4 at laptop ~ $ pass match .com
+.br
+Search Terms: .com
+.br
+Business/some-silly-business-site.com [y/N]:
+.br
+Email/donenfeld.com [y/N]: y
+.br
+sup3rh4x3rizmynam3
+.br
+Email/zx2c4.com [y/N]: n
+.br
+
+.br
+Notice that loop continues with next matching password, even if user requested print.
+.TP
Show existing password
.B zx2c4 at laptop ~ $ pass Email/zx2c4.com
.br
diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..6ccfb85 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -415,6 +415,28 @@ cmd_find() {
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'
}
+cmd_match() {
+ [[ $# -eq 0 ]] && die "Usage: $PROGRAM $COMMAND pass-name"
+ IFS="," eval 'echo "Search Terms: $*"'
+ local terms="*$(printf '%s*|*' "$@")"
+ local passfile passfile_orig results
+ while read -r -d "" passfile_orig; do
+ [[ $? -ne 0 ]] && continue
+ passfile="${passfile_orig%.gpg}"
+ passfile="${passfile#$PREFIX/}"
+ local passfile_dir="${passfile%/*}/"
+ [[ $passfile_dir == "${passfile}/" ]] && passfile_dir=""
+ passfile="${passfile##*/}"
+ printf "\e[94m%s\e[1m%s\e[0m [y/N]:" "$passfile_dir" "$passfile"
+ read -r response </dev/tty
+ if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
+ then
+ results="$($GPG -d "${GPG_OPTS[@]}" "$passfile_orig")"
+ echo "$results"
+ fi
+ done < <(find -L "$PREFIX" -path '*/.git' -prune -o -ipath "${terms%|*}.gpg" -print0)
+}
+
cmd_grep() {
[[ $# -lt 1 ]] && die "Usage: $PROGRAM $COMMAND [GREPOPTIONS] search-string"
local passfile grepresults
@@ -706,6 +728,7 @@ case "$1" in
version|--version) shift; cmd_version "$@" ;;
show|ls|list) shift; cmd_show "$@" ;;
find|search) shift; cmd_find "$@" ;;
+ match) shift; cmd_match "$@" ;;
grep) shift; cmd_grep "$@" ;;
insert|add) shift; cmd_insert "$@" ;;
edit) shift; cmd_edit "$@" ;;
--
2.20.1
More information about the Password-Store
mailing list