[PATCH-RESEND] Allow specifing the extension to add to edit temp files

Thomas Spurden thomas at spurden.name
Fri Jul 26 21:55:34 CEST 2019


I sent this patch to the mailing list in September 2018, after a bit of
discussion about my issue with storing LibreOffice documents in a password
store: I store various documents in a password store and set EDITOR=xdg-open.
LibreOffice depends on the file extension to determine the document type - it
assumes a .txt file is a text document.

With this change I can set PASSWORD_STORE_EDIT_EXT="" in my wrapper script and
it all works (the file extension is unchanged), but the default behaviour
remains to add .txt.

I was wondering if there is any chance of it being integrated into pass, or it
too niche?

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(-)

diff --git a/man/pass.1 b/man/pass.1
index a555dcb..ab5f300 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -122,7 +122,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
@@ -449,6 +450,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 1d119f2..b071256 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:]}"
+EDIT_EXT="${PASSWORD_STORE_EDIT_EXT-.txt}"
 
 export GIT_CEILING_DIRECTORIES="$PREFIX/.."
 
@@ -490,7 +491,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.22.0



More information about the Password-Store mailing list