[pass] pass and fzf

pc re pcre at gmx.de
Tue Sep 29 15:13:03 CEST 2015


Fuzzy search with pass using fzf

To use "pass **<TAB>" or "pass -c **"

modify fzf/shell/completion.bash or completion.zsh

x_cmds="kill ssh telnet unset unalias export pass"

# Passwordstore completion
complete -F _fzf_pass_completion -o default -o bashdefault pass

_fzf_pass_completion() {
    _fzf_list_completion '+m' "$@" << "EOF"
    find ~/.password-store/ -name "*.gpg" | sed -r
's,(.*)\.password-store/(.*    )\.gpg,\2,'
EOF
}

Maybe we could make a patch for fzf so it supports passwordstore.

cheers


Am 28.09.2015 um 19:09 schrieb password-store-request at lists.zx2c4.com:
> Send Password-Store mailing list submissions to
> 	password-store at lists.zx2c4.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://lists.zx2c4.com/mailman/listinfo/password-store
> or, via email, send a message with subject or body 'help' to
> 	password-store-request at lists.zx2c4.com
>
> You can reach the person managing the list at
> 	password-store-owner at lists.zx2c4.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Password-Store digest..."
>
>
> Today's Topics:
>
>    1. Re: [PATCH] Fuzzy lookup for "show" command (Matthias Beyer)
>    2. Re: [PATCH] Fuzzy lookup for "show" command (Michael Traxler)
>    3. Re: [PATCH] Fuzzy lookup for "show" command (Matthias Beyer)
>    4. Re: [PATCH] Fuzzy lookup for "show" command (Markus Unterwaditzer)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 28 Sep 2015 13:54:22 +0200
> From: Matthias Beyer <mail at beyermatthias.de>
> To: David Vogt <david.vogt at adfinis-sygroup.ch>
> Cc: password-store at lists.zx2c4.com
> Subject: Re: [pass] [PATCH] Fuzzy lookup for "show" command
> Message-ID: <20150928115422.GC3455 at yuu>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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 <david.vogt at adfinis-sygroup.ch>
>> 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
>> Password-Store at lists.zx2c4.com
>> http://lists.zx2c4.com/mailman/listinfo/password-store
>



More information about the Password-Store mailing list