[PATCH] Keep existing file extension for edit command

Thomas Spurden thomas at spurden.name
Tue Sep 4 20:47:06 CEST 2018


If the file doesn't have an extension then add .txt as before.
---
 src/password-store.sh | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Hi,

I store various documents (PDFs, office docs) in a password store, and have an
alias which sets EDITOR=xdg-open. In general this seems to work well; PDFs and
images all seem to work properly. However Libreoffice appears to examine the
file extension to determine what to do with a file it is asked to open. So
xdg-open will correctly launch Libreoffice, but then Libreoffice will attempt to
import the document as a text file! This minor modification to keep the existing
file extension makes Libreoffice happy. I guess it would also help with mime
types that xdg-open detects only based on file extension (as opposed to file
header), but I don't think I use any of those in my document store.

Does this seem like a sensible thing to do?

If so, does this implementation seem like a sensible way to do it?

Thanks,
Tom

diff --git a/src/password-store.sh b/src/password-store.sh
index d89d455..073e467 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -473,8 +473,15 @@ cmd_edit() {
 	local passfile="$PREFIX/$path.gpg"
 	set_git "$passfile"
 
+	local addext=".txt"
+	local base=$(basename "$path")
+	local noext=${base%.*}
+	if [[ "$noext" != "$base" ]]; then
+		addext=""
+	fi
+
 	tmpdir #Defines $SECURE_TMPDIR
-	local tmp_file="$(mktemp -u "$SECURE_TMPDIR/XXXXXX")-${path//\//-}.txt"
+	local tmp_file="$(mktemp -u "$SECURE_TMPDIR/XXXXXX")-${path//\//-}${addext}"
 
 	local action="Add"
 	if [[ -f $passfile ]]; then
-- 
2.18.0



More information about the Password-Store mailing list