Working proof-of-concept patch attached. The result is not exactly like specified and some limitations apply.
For instance: pass -f googleano results in no hit. And: pass -f google*ano works but will not print the matched entry due to "cmd_find" not accepting this syntax. Cheers, Renato On 25/03/16 05:26, Gabriel Filion wrote: > Renato Alves: >> Hi everyone, >> >> Would it be possible to include an option in "pass show" to behave like >> "pass find" and if only one entry is matched, use it? > > I'd personally like it very much to have this kind of functionality > >> The interface I have in mind is something like: >> >> % pass -f mozilla >> (stderr) Found unique match web/mozilla.org/username >> (stdout) <decrypted password> >> (exitcode) 0 >> >> % pass -f google >> (stderr) Multiple matches found: >> (stdout) Search Terms: google >> (stdout) └── web >> (stdout) └── google.com >> (stdout) ├── user >> (stdout) └── anotheruser >> (exitcode) 1 >> >> % pass -f googleano >> (stderr) Found unique match web/google.com/anotheruser >> (stdout) <decrypted password> >> (exitcode) 0 >> >> >> where "pass -f" == "pass show -f" and -f stands for "--find" or "--fuzzy". > > > > > _______________________________________________ > Password-Store mailing list > [email protected] > http://lists.zx2c4.com/mailman/listinfo/password-store >
From 555b459629cee543d8c160fe8758c0ab4fa34bb2 Mon Sep 17 00:00:00 2001 From: Renato Alves <[email protected]> Date: Tue, 29 Mar 2016 00:26:20 +0200 Subject: [PATCH] Add fuzzy option to pass --- bin/pass | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/pass b/bin/pass index 63be840..5ada7b1 100755 --- a/bin/pass +++ b/bin/pass @@ -295,12 +295,13 @@ cmd_init() { } cmd_show() { - local opts clip_location clip=0 - opts="$($GETOPT -o c:: -l clip:: -n "$PROGRAM" -- "$@")" + local opts clip_location clip=0 fuzzy=0 + opts="$($GETOPT -o c::f -l clip::fuzzy -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" while true; do case $1 in -c|--clip) clip=1; clip_location="${2:-1}"; shift 2 ;; + -f|--fuzzy) fuzzy=1; shift ;; --) shift; break ;; esac done @@ -309,6 +310,19 @@ cmd_show() { local path="$1" local passfile="$PREFIX/$path.gpg" check_sneaky_paths "$path" + + if [[ $fuzzy -eq 1 ]]; then + local matches=( $(find ${PREFIX} -type f -ipath "*${path}*") ) + + if [[ ${#matches[@]} -eq 1 ]]; then + cmd_find $path + passfile=${matches[0]} + else + cmd_find $path + die "Error: Fuzzy search found multiple matches" + fi + fi + if [[ -f $passfile ]]; then if [[ $clip -eq 0 ]]; then $GPG -d "${GPG_OPTS[@]}" "$passfile" || exit $? -- 2.6.0
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Password-Store mailing list [email protected] http://lists.zx2c4.com/mailman/listinfo/password-store
