Get field value for command show and option -c

Adrien Horgnies ah at fita.dev
Wed Feb 28 17:49:38 UTC 2024


Hi,

You can certainly handle selecting part of your password-store entry
outside password-store.
But then you need to handle clearing the clipboard yourself.
Furthermore, I much prefer calling `pass -cuser foo` than `pass foo |
yq .foo | wl-copy`.

While the current code doesn't enforce any file format, I think it's
impractical to use with any file format.

But you did bring to my attention that it would be better to keep
password-store file format agnostic.
Thus, to achieve the same purpose, I propose the patch below instead.
The idea is to introduce an extension point that lets the user specify
whatever he want to parse the entry.

Damien would be able to do:

$ export PASSWORD_STORE_CONTENT_SELECTOR=yq
$ pass -c.user foo

And I would be able to do something similar with my own script.

I'll look more into the extensions, but I felt like it wouldn't be well
integrated.

Thanks for the feedback,

Adrien Horgnies

>From c50b60f506de281f2fa830e03d815d6825b549c8 Mon Sep 17 00:00:00 2001
From: Adrien Horgnies <ah at fita.dev>
Date: Wed, 28 Feb 2024 17:52:13 +0100
Subject: [PATCH] Add ability to customize how show selects content

When using options -c or -q, the argument value is assumed to be a line number.
And the given line is copied or QR encoded.

With the environment variable PASSWORD_STORE_CONTENT_SELECTOR,
 the user is now able customize what part of the password store entry
is selected.

PASSWORD_STORE_CONTENT_SELECTOR must be an executable command.
The whole entry is given through stdin.
The value of -c and -q are passed as argument $1.
And stdout is copied or QR encoded.
---
 src/password-store.sh | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 22e818f..e8c7a79 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -19,6 +19,7 @@ CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
 GENERATED_LENGTH="${PASSWORD_STORE_GENERATED_LENGTH:-25}"
 CHARACTER_SET="${PASSWORD_STORE_CHARACTER_SET:-[:punct:][:alnum:]}"
 CHARACTER_SET_NO_SYMBOLS="${PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS:-[:alnum:]}"
+CONTENT_SELECTOR="${PASSWORD_STORE_CONTENT_SELECTOR}"

 unset GIT_DIR GIT_WORK_TREE GIT_NAMESPACE GIT_INDEX_FILE
GIT_INDEX_VERSION GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
 export GIT_CEILING_DIRECTORIES="$PREFIX/.."
@@ -387,9 +388,14 @@ cmd_show() {
             pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | $BASE64)" || exit $?
             echo "$pass" | $BASE64 -d
         else
-            [[ $selected_line =~ ^[0-9]+$ ]] || die "Clip location
'$selected_line' is not a number."
-            pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n
+${selected_line} | head -n 1)" || exit $?
-            [[ -n $pass ]] || die "There is no password to put on the
clipboard at line ${selected_line}."
+            if [[ -n "$CONTENT_SELECTOR" ]]; then
+                pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" |
$CONTENT_SELECTOR "${selected_line}")" || exit $?
+                [[ -n $pass ]] || die "There is no password to put on
the clipboard with key ${selected_line}."
+            else
+                [[ $selected_line =~ ^[0-9]+$ ]] || die "Clip
location '$selected_line' is not a number."
+                pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | tail
-n +${selected_line} | head -n 1)" || exit $?
+                [[ -n $pass ]] || die "There is no password to put on
the clipboard at line ${selected_line}."
+            fi
             if [[ $clip -eq 1 ]]; then
                 clip "$pass" "$path"
             elif [[ $qrcode -eq 1 ]]; then
-- 
2.34.1


More information about the Password-Store mailing list