[pass] [PATCH] add field option to the show command.

Johan Venant jvenant at invicem.pro
Wed Mar 26 15:17:10 CET 2014


Made a little mistake : forgot the ":" after field in opts


*--------Johan Venant.*
Tel : +33 6 13 06 95 43
*www.invicem.pro <http://www.invicem.pro>*





On Wed, Mar 26, 2014 at 9:46 AM, jvenant <jvenant at invicem.pro> wrote:

>  Add the capacity to output or copy in the clipboard only
>  the specified field instead of the password.
>  Using the standard format : <field>: <value> in the password data
> ---
>  src/password-store.sh | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/src/password-store.sh b/src/password-store.sh
> index c576844..05ff927 100755
> --- a/src/password-store.sh
> +++ b/src/password-store.sh
> @@ -230,12 +230,14 @@ case "$command" in
>                 ;;
>         show|ls|list)
>                 clip=0
> +               field=""
>
> -               opts="$($GETOPT -o c -l clip -n "$program" -- "$@")"
> +               opts="$($GETOPT -o cf: -l clip,field -n "$program" --
> "$@")"
>                 err=$?
>                 eval set -- "$opts"
>                 while true; do case $1 in
>                         -c|--clip) clip=1; shift ;;
> +                       -f|--field) field="$2"; shift 2 ;;
>                         --) shift; break ;;
>                 esac done
>
> @@ -248,11 +250,20 @@ case "$command" in
>                 passfile="$PREFIX/$path.gpg"
>                 if [[ -f $passfile ]]; then
>                         if [[ $clip -eq 0 ]]; then
> -                               exec $GPG -d $GPG_OPTS "$passfile"
> +
> +                               if [[ -n $field ]]; then
> +                                       exec $GPG -d $GPG_OPTS "$passfile"
> | sed -n "/^$field: / s/$field: //p"
> +                               else
> +                                       exec $GPG -d $GPG_OPTS "$passfile"
> +                               fi
>                         else
> -                               pass="$($GPG -d $GPG_OPTS "$passfile" |
> head -n 1)"
> -                               [[ -n $pass ]] || exit 1
> -                               clip "$pass" "$path"
> +                               if [[ -n $field ]]; then
> +                                       field="$($GPG -d $GPG_OPTS
> "$passfile" | sed -n "/^$field: / s/$field: //p")"
> +                               else
> +                                       field="$($GPG -d $GPG_OPTS
> "$passfile" | head -n 1)"
> +                               fi
> +                               [[ -n $field ]] || exit 1
> +                               clip "$field" "$path"
>                         fi
>                 elif [[ -d $PREFIX/$path ]]; then
>                         if [[ -z $path ]]; then
> --
> 1.9.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20140326/a05524f7/attachment.html>


More information about the Password-Store mailing list