[PATCH] Added wild-card capability to the show command.

Nobutarou Nosuke nobutarounosuke at gmail.com
Thu Apr 5 01:25:50 CEST 2018


Hello,

Did you use peco or fzf with your past one-liner (
https://github.com/peco/peco, https://github.com/junegunn/fzf)? They are
very nice filtering tools. For reference, here is my dirty script with
peco, https://github.com/Nobutarou/passpeco. You can find
"wc-demo/dir-demo2/0-current"
by just typing "wc- demo2 cur"

Regards,
Nobuyuki


2018年4月5日木曜日、Trey Mitchell<treym at wolfram.com>さんは書きました:

> Due to the nature of our environment it's sometimes necessary to iterate
> through a bunch of old passwords before finding the one I need.
> So I wanted to be able to list more than one password in a directory at a
> time. I was previously using shell one-liners to accomplish this but
> finally got around to just adding the functionality. It may not make sense
> for anyone else, but I figured I'd submit it anyway on the off chance that
> someone else found it useful.
>
> Example:
>
> Given this structure
> $ pass wc-demo/
> wc-demo/
> ├── 0-current
> ├── 1-old
> ├── dir-demo1
> │   ├── 0-current
> │   └── 1-old
> └── dir-demo2
>     ├── 0-current
>     └── 1-old
>
> All of these work:
> $ pass wc-demo/*
> wc-demo/0-current:
> pass1
>
> wc-demo/1-old:
> pass2
>
> $ pass wc-demo/dir*
> wc-demo/dir-demo1
> ├── 0-current
> └── 1-old
> wc-demo/dir-demo2
> ├── 0-current
> └── 1-old
>
> $ pass wc-demo/dir*/*
> wc-demo/dir-demo1/0-current:
> pass2
>
> wc-demo/dir-demo1/1-old:
> oldpass
>
> wc-demo/dir-demo2/0-current:
> pass#1
>
> wc-demo/dir-demo2/1-old:
> A@|FVz}W=w1A at ZkzXD*2WxA2X
>
> $ pass wc-demo/dir-demo1/*
> wc-demo/dir-demo1/0-current:
> pass2
>
> wc-demo/dir-demo1/1-old:
> oldpass
>
> All existing functionality is preserved.
>
> Let me know if you want me to revise or clean up the code in any way.
>
> From abe2089d0d5e76145fec26953a900da695c52d72 Mon Sep 17 00:00:00 2001
> From: Trey Mitchell <treym at wolfram.com>
> Date: Fri, 30 Mar 2018 19:06:30 -0500
> Subject: [PATCH] Added wild-card capability to the show command.
>
> ---
>  src/password-store.sh | 71 ++++++++++++++++++++++++++++++
> ++++-----------------
>  1 file changed, 48 insertions(+), 23 deletions(-)
>
> diff --git a/src/password-store.sh b/src/password-store.sh
> index eac5404..aa69ac0 100755
> --- a/src/password-store.sh
> +++ b/src/password-store.sh
> @@ -358,33 +358,58 @@ cmd_show() {
>         [[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die
> "Usage: $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]]
> [--qrcode[=line-number],-q[line-number]] [pass-name]"
>
>         local path="$1"
> -       local passfile="$PREFIX/$path.gpg"
>         check_sneaky_paths "$path"
> -       if [[ -f $passfile ]]; then
> -               if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then
> -                       $GPG -d "${GPG_OPTS[@]}" "$passfile" || exit $?
> -               else
> -                       [[ $selected_line =~ ^[0-9]+$ ]] || die "Clip
> location '$selected_line' is not a number."
> -                       local pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile"
> | tail -n +${selected_line} | head -n 1)"
> -                       [[ -n $pass ]] || die "There is no password to put
> on the clipboard at line ${selected_line}."
> -                       if [[ $clip -eq 1 ]]; then
> -                               clip "$pass" "$path"
> -                       elif [[ $qrcode -eq 1 ]]; then
> -                               qrcode "$pass" "$path"
> +       local passfiles="$PREFIX/$path.gpg"
> +       local ARRAY=($passfiles)
> +
> +       if [[ $clip -eq 1 && ${#ARRAY[@]} -gt 1 ]]; then
> +               die "Clip makes no sense in multi record context."
> +       fi
> +
> +       for passfile in $passfiles; do
> +               local passpath=${passfile#$PREFIX\/}
> +               local passpath=${passpath%\.gpg}
> +               local passdir=${passfile%\.gpg}
> +               local passdirlong=($(ls -d $passdir 2>/dev/null))
> +               local passdirshort=${passdirlong#$PREFIX\/}
> +               if [[ -f $passfile ]]; then
> +                       if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then
> +                               if [ ${#ARRAY[@]} -gt 1 ]; then
> +                                       printf "$passpath:\n"
> +                                       $GPG -d "${GPG_OPTS[@]}"
> "$passfile" || exit $?
> +                                       printf "\n"
> +                               else
> +                                       $GPG -d "${GPG_OPTS[@]}"
> "$passfile" || exit $?
> +                               fi
> +                       else
> +                               [[ $selected_line =~ ^[0-9]+$ ]] || die
> "Clip location '$selected_line' is not a number."
> +                               local pass="$($GPG -d "${GPG_OPTS[@]}"
> "$passfile" | tail -n +${selected_line} | head -n 1)"
> +                               [[ -n $pass ]] || die "There is no
> password to put on the clipboard at line ${selected_line}."
> +                               if [[ $clip -eq 1 ]]; then
> +                                       clip "$pass" "$path"
> +                               elif [[ $qrcode -eq 1 ]]; then
> +                                       if [ ${#ARRAY[@]} -gt 1 ]; then
> +                                               printf "$passpath:\n"
> +                                       fi
> +                                       qrcode "$pass" "$passpath"
> +                               fi
>                         fi
> -               fi
> -       elif [[ -d $PREFIX/$path ]]; then
> -               if [[ -z $path ]]; then
> -                       echo "Password Store"
> +               elif [[ -d ${passdirlong[0]} ]]; then
> +                       if [[ -z $path ]]; then
> +                               echo "Password Store"
> +                               tree -C -l --noreport "$PREFIX" | tail -n
> +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of
> line, but keep colors
> +                       else
> +                               for dir in "${passdirlong[@]}"; do
> +                               echo ${dir#$PREFIX\/}
> +                               tree -C -l --noreport "$dir" | tail -n +2
> | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of
> line, but keep colors
> +                               done
> +                       fi
> +               elif [[ -z $path ]]; then
> +                       die "Error: password store is empty. Try \"pass
> init\"."
>                 else
> -                       echo "${path%\/}"
> +                       die "Error: $path is not in the password store."
>                 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
> -       elif [[ -z $path ]]; then
> -               die "Error: password store is empty. Try \"pass init\"."
> -       else
> -               die "Error: $path is not in the password store."
> -       fi
> +       done
>  }
>
>  cmd_find() {
> --
> 2.14.1
>
>
>
> --
> Trey Mitchell
> Wolfram Research, Inc
> Systems Administrator, Dev/Ops
> 217-398-0700
> _______________________________________________
> Password-Store mailing list
> Password-Store at lists.zx2c4.com
> https://lists.zx2c4.com/mailman/listinfo/password-store
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20180405/6e6f17a1/attachment-0001.html>


More information about the Password-Store mailing list