[pass] [PATCH] fix .gpg stripping for BSD sed, differentiate between GNU sed (-r) and BSD sed (-E)

Lorenz Weber mail at lenzw.de
Mon May 11 14:00:47 CEST 2015


Am 11.05.2015 um 13:52 schrieb Jason A. Donenfeld:
> Can we figure out a way to do this without needing to differentiate between GNU sed and BSD sed?


phew. maybe. but all solutions are quite ugly. I'll just quote myself from back then on the mailing list ;)

---

GNU sed allows use of the switch -E since version 4.2 with the code comment
 /* Undocumented, for compatibility with BSD sed.  */
(it's not even mentioned in the Changelog)

As this version has been around since April 2009, most distributions
should have picked up on this.

So [...] what should the course of
action be?

* go with the -E option for both versions of sed
* distinguish GNU sed from BSD sed and apply -r or -E accordingly
* replace the current sed comand with two sed commands, something like
tree -C -l --noreport "$PREFIX/$path" | tail -n +2 \
| sed 's/\.gpg\(\x1B\[[0-9]\+m\)\{0,1\} ->/\1/' \
| sed 's/\.gpg\(\x1B\[[0-9]\+m\)\{0,1\}$/\1/'


While the first option would make the most readable regex and require
only one call to sed, the last option should be the most hassle-free and
compatible, but with the most ugly regex (especially having to use
'\{0,1\}' instead of '?' sickens me).

---

an additional comment came up since then: sed for BSD officially allows for '-r' in newer versons - but that option has never made it's way to OSX, so I guess we can't go that way


More information about the Password-Store mailing list