From e43eb1177872f52e949fb5f0f93396ed94b0d093 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 2 Aug 2026 14:48:29 +0200 Subject: move to chezmoi --- home/dot_local/share/bin/executable_decsync2plain | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 home/dot_local/share/bin/executable_decsync2plain (limited to 'home/dot_local/share/bin/executable_decsync2plain') diff --git a/home/dot_local/share/bin/executable_decsync2plain b/home/dot_local/share/bin/executable_decsync2plain new file mode 100644 index 0000000..745a1c2 --- /dev/null +++ b/home/dot_local/share/bin/executable_decsync2plain @@ -0,0 +1,60 @@ +#!/bin/sh + +EXEC_NAME="$(basename "$0")" +EXTENSION="$1" + +usage() { + cat << EOF +usage: $EXEC_NAME [EXT] + +examples: + cd Decsync/calendars/$(uuidgen)/v2/DeviceName-DecSyncCC-$RANDOM ; $EXEC_NAME ics + + cd Decsync/contacts/$(uuidgen)/v2/DeviceName-DecSyncCC-$RANDOM ; $EXEC_NAME vcf + +$EXEC_NAME will attempt to guess the appropriate file extension based on the parent folder names. the first parent folder that matches exactly one of the following determines the file extension: + calendars -> .ics + contacts -> .vcf + tasks -> .ics + +if no file extension is found and none is explicitly provided, $EXEC_NAME will exit. +EOF +} + +if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then + usage + exit 0 +fi + +if [ ! -e sequences ] ; then + echo "error: could not find decsync sequences file" + exit 1 +fi + +# auto detect extension if not explicitly provided +if [ -z "$EXTENSION" ] ; then + EXTENSION="$(realpath "$PWD" | tr '/' '\n' | tac | while read -r folder ; do + case "$folder" in + calendars|tasks) echo ics ; break ;; + contacts) echo vcf ; break ;; + esac + done)" +fi + +if [ -z "$EXTENSION" ] ; then + echo "error: could not detect EXT" + exit 1 +fi + +COLLECTION_PREFIX="$(jq --raw-output 'if .[2] == "name" then "\(.[3])/" else empty end' info)" +mkdir -p "$COLLECTION_PREFIX" + +jq --raw-output '. | keys | join("\n")' sequences |\ + sed '/^info$/d' |\ + tr '\n' '\0' |\ + xargs -0 -n1 cat |\ +while read -r line ; do + filename="$COLLECTION_PREFIX$(echo "$line" | jq --raw-output '.[0][1]').$EXTENSION" + echo "$filename" + echo "$line" | jq --raw-output '.[3]' > "$filename" +done -- cgit v1.2.3