Hi,

please do not apply this patch.

This very behaviour can be replicated using a fuzzy-completion tools
like fzf[0], like so:

    fuzzpass() {
        local path=$(find ~/.password-store/ -name "*.gpg"  | \
            sed -r 's,(.*)\.password-store/(.*)\.gpg,\2,'   | \
            fzf +m);
        [[ ! -z "$path" ]] && pass -c $path
    }

And fzf is really damn fast and really stable (I'm using it for years
now). I think such functionality shouldn't be integrated in pass
because there are already mature tools around which enable one to
implement such a thing.

[0]: https://github.com/junegunn/fzf

Regards.

On 28-09-2015 11:07:15, David Vogt wrote:
> Hi Guys
> 
> I really like pass, but a feature that I'm missing is to quickly fetch a
> password if I have a nested structure. For example, I have my passwords
> sorted into a lot of subfolders. Now usually the password file's name is
> still unique, but nested somewhere deep.
> 
> So I've hacked up an extension for the "show" command that allows
> searching for a password file within the tree structure. The attached
> patch allows for matching anywhere inside the path to the file using Awk.
> 
> Please have a look and let me know what you think. Note that I'm not
> really a shell dev, so this may still be quite buggy..
> 
> 
> Best,
> David
> 
> -- 
> Adfinis SyGroup AG     | David Vogt, Bereichsleiter Software-Entwicklung
> Keltenstrasse 98       | CH-3018 Bern
> 
> PGP ID 23F1F230 | Tel. +41 (0) 31 550 31 11 | Direct +41 (0)31 550 31 12
> PGP fingerprint : 4E62 977E BA2C EC6A 8346  127B FDC9 6CFA 23F1 F230

> From 2725b5dbb3caf939a1baa3c9a433fabb05926200 Mon Sep 17 00:00:00 2001
> From: David Vogt <[email protected]>
> Date: Mon, 28 Sep 2015 10:20:38 +0200
> Subject: [PATCH] Implement fuzzy finding for the "show" subcommand.
> 
> If you pass in "-z" or --fuzzy as a parameter to "show", you can
> match any file in your password store instead of having to pass
> the whole path. This may be more convenient than tab-completing.
> ---
>  src/password-store.sh | 41 ++++++++++++++++++++++++++++++++++-------
>  1 file changed, 34 insertions(+), 7 deletions(-)
> 
> diff --git a/src/password-store.sh b/src/password-store.sh
> index d535a74..a4660e2 100755
> --- a/src/password-store.sh
> +++ b/src/password-store.sh
> @@ -223,9 +223,12 @@ cmd_usage() {
>               List passwords.
>           $PROGRAM find pass-names...
>               List passwords that match pass-names.
> -         $PROGRAM [show] [--clip,-c] pass-name
> +         $PROGRAM [show] [--clip,-c] [--fuzzy,-z] pass-name
>               Show existing password and optionally put it on the clipboard.
>               If put on the clipboard, it will be cleared in $CLIP_TIME 
> seconds.
> +             If -z or --fuzzy is given, the pass-name will be searched for,
> +             so instead of passing in 'foo/bar/baz', you can just give 'baz'
> +             (provided that 'baz' is unique).
>           $PROGRAM grep search-string
>               Search for password files containing search-string when 
> decrypted.
>           $PROGRAM insert [--echo,-e | --multiline,-m] [--force,-f] pass-name
> @@ -257,6 +260,28 @@ cmd_usage() {
>       _EOF
>  }
>  
> +find_fuzzy_if() {
> +     local path="$1"
> +     local fuzzy="$2"
> +
> +     if [[ -z "$path" ]]; then
> +             return
> +     fi
> +
> +     if [[ "$fuzzy" -ne 1 ]]; then
> +             echo "$path"
> +             return
> +     fi
> +
> +     echo "Fuzzy matching *$1*" >&2
> +     (
> +             cd "$PREFIX"
> +             find . -path ./.git -prune -o -type f \
> +                     | awk "/$path/ "'{ $file=substr($0, 3, length($0)-6); 
> print $file }'
> +     )
> +     exit
> +}
> +
>  cmd_init() {
>       local opts id_path=""
>       opts="$($GETOPT -o p: -l path: -n "$PROGRAM" -- "$@")"
> @@ -294,18 +319,20 @@ cmd_init() {
>  }
>  
>  cmd_show() {
> -     local opts clip=0
> -     opts="$($GETOPT -o c -l clip -n "$PROGRAM" -- "$@")"
> +     local opts fuzzy=0 clip=0
> +     opts="$($GETOPT -o c,z -l clip,fuzzy -n "$PROGRAM" -- "$@")"
>       local err=$?
>       eval set -- "$opts"
> -     while true; do case $1 in
> -             -c|--clip) clip=1; shift ;;
> +     while true; do case "$1" in
> +             -c|--clip)  clip=1;  shift; ;;
> +             -z|--fuzzy) fuzzy=1; shift; ;;
>               --) shift; break ;;
>       esac done
>  
> -     [[ $err -ne 0 ]] && die "Usage: $PROGRAM $COMMAND [--clip,-c] 
> [pass-name]"
> +     [[ $err -ne 0 ]] && die "Usage: $PROGRAM $COMMAND [--clip,-c] 
> [--fuzzy,-z] [pass-name]"
> +
> +     local path="$(find_fuzzy_if "$1" $fuzzy)"
>  
> -     local path="$1"
>       local passfile="$PREFIX/$path.gpg"
>       check_sneaky_paths "$path"
>       if [[ -f $passfile ]]; then
> -- 
> 2.5.2
> 




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


-- 
Mit freundlichen Grüßen,
Kind regards,
Matthias Beyer

Proudly sent with mutt.
Happily signed with gnupg.

Attachment: pgpzYe57RduWp.pgp
Description: PGP signature

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

Reply via email to