[PATCH] Keep existing file extension for edit command

Thomas Spurden thomas at spurden.name
Tue Sep 4 21:57:37 CEST 2018


Excerpts from Jason A. Donenfeld's message of September 4, 2018 7:53 pm:
> Nice idea, but is there a cleaner way to do this using the default
> assignment operator, avoiding the call to basename, and not adding a
> conditional?

I did have a little play around when I was writing the patch (it was a few weeks
ago), I should have made notes! Ideally there would be some bash expansion which
would give either the file extension or an empty string, but this seems quite
tricky to me. ${name%%*.} leaves you with the whole filename when it doesn't
have an extension.

I think the invocation of basename can be eliminated by using ${path##*/} (strip
off the longest match of '*/').

Then the tricky bit is adding the .txt only when the filename doesn't already
have an extension. Based on some internetting I have created this:

	case "${path##*/}" in
		*.*) txtpath="$path";;
		*) txtpath="$path.txt";;
	esac

Not sure if that is better. What do you think?


More information about the Password-Store mailing list