Restore dates and names on /e/'s Notes export
/e/'s Notes app can export local notes to .md files. However, it encodes the timestamp as a -YYYYMMDD-HHMMSS suffix on the file name. This is fair enough as dates and times can be unreliable on certain devices and over copies, but it's a bit annoying when "importing" them back (see below). To fix this, I did the following on my computer's Nextcloud sync:
find . -type f -name '*-*-*.md' | sed -r 's/^(.*)-([0-9]{4})([0-9]{2})([0-9]{2})-([0-9]{2})([0-9]{2})([0-9]{2}).md/\2-\3-\4 \5:\6:\7 \1/' | while read -r d t f ; do
p="$f-$(echo "$d" | tr -d -)-$(echo "$t" | tr -d :).md"
f="$f.md"
# update the date and time
touch -d "$d $t" "$p"
# move to the un-suffixed name
mv -v "$p" "$f"
done
I certainly won't win any beauty or quality contest with this code, but this was enough for Nextcloud and the Notes app to pick it up, yay!
Note that the Notes app is a bit silly about backups: it allows to export local notes, but not to import them back. Only solution for doing so is either to re-create them manually (even though I could open each file separately read-only, I couldn't even find a solution to import them one by one), or use some "Murena" account (so either a "true" murena.io, or another Nextcloud host). I did the latter because I have access to a Nextcloud instance already, but I don't quite like the tie-in to a cloud provider -- especially when you can export them already, so there ought to be a no-so-complicated way of importing, doesn't it?
I'm not blaming this on Murena just yet because Notes is a fork of Nextcloud Notes, which might not have the feature itself -- but still, sad.
— Permalink
