[PATCH] Allow specifying the extension to add to edit temp files

Thomas Spurden thomas at spurden.name
Fri Sep 7 09:40:35 CEST 2018


PASSWORD_STORE_EDIT_EXT (defaults to .txt if not set) is appended to the
filename of temporary files created by edit.
---
 man/pass.1            | 7 ++++++-
 src/password-store.sh | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

This is a simple way of solving my problem (I can just set another env var in my
wrapper script) without changing existing default behaviour. Not sure if having
more environment variables for configuration is a worry?

diff --git a/man/pass.1 b/man/pass.1
index 01a3fbe..0f01bbe 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -120,7 +120,8 @@ by the environment variable \fIEDITOR\fP or using
 as a fallback. This mode makes use of temporary files for editing, but care is taken to
 ensure that temporary files are created in \fI/dev/shm\fP in order to avoid writing to
 difficult-to-erase disk sectors. If \fI/dev/shm\fP is not accessible, fallback to
-the ordinary \fITMPDIR\fP location, and print a warning.
+the ordinary \fITMPDIR\fP location, and print a warning. The temporary filename
+has \fI.txt\fP (or \fIPASSWORD_STORE_EDIT_EXT\fP) appended to it.
 .TP
 \fBgenerate\fP [ \fI--no-symbols\fP, \fI-n\fP ] [ \fI--clip\fP, \fI-c\fP ] [ \fI--in-place\fP, \fI-i\fP | \fI--force\fP, \fI-f\fP ] \fIpass-name [pass-length]\fP
 Generate a new password using \fB/dev/urandom\fP of length \fIpass-length\fP
@@ -445,6 +446,10 @@ by \fBtr\fP. See
 .BR tr (1)
 for more info.
 .TP
+.I PASSWORD_STORE_EDIT_EXT
+Sets the text to append to temporary files created for \fBedit\fP. Defaults to
+\fI.txt\fP if not set. May be set to an empty string.
+.TP
 .I PASSWORD_STORE_ENABLE_EXTENSIONS
 This environment variable must be set to "true" for extensions to be enabled.
 .TP
diff --git a/src/password-store.sh b/src/password-store.sh
index d89d455..06d5614 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:-[:graph:]}"
 CHARACTER_SET_NO_SYMBOLS="${PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS:-[:alnum:]}"
+EDIT_EXT="${PASSWORD_STORE_EDIT_EXT-.txt}"
 
 export GIT_CEILING_DIRECTORIES="$PREFIX/.."
 
@@ -474,7 +475,7 @@ cmd_edit() {
 	set_git "$passfile"
 
 	tmpdir #Defines $SECURE_TMPDIR
-	local tmp_file="$(mktemp -u "$SECURE_TMPDIR/XXXXXX")-${path//\//-}.txt"
+	local tmp_file="$(mktemp -u "$SECURE_TMPDIR/XXXXXX")-${path//\//-}${EDIT_EXT}"
 
 	local action="Add"
 	if [[ -f $passfile ]]; then
-- 
2.18.0



More information about the Password-Store mailing list