Astroport.ONE/RUNTIME/TW/delete_tiddler.sh

34 lines
820 B
Bash
Raw Normal View History

2024-04-21 22:55:49 +02:00
#!/bin/bash
2024-04-22 19:17:32 +02:00
# Generate a unique timestamp
2024-04-21 22:55:49 +02:00
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
2024-04-22 19:17:32 +02:00
# Check if TiddlyWiki file exists
2024-04-21 22:55:49 +02:00
TW="$1"
2024-04-22 19:17:32 +02:00
[[ ! -s $TW ]] && echo "No TiddlyWiki found at: $TW" && exit 1
# Check if Tiddler title is provided
2024-04-21 22:55:49 +02:00
TITLE="$2"
2024-04-22 19:17:32 +02:00
[[ -z $TITLE ]] && echo "Need a Tiddler title" && exit 1
2024-04-21 22:55:49 +02:00
2024-04-22 19:17:32 +02:00
# Delete the specified Tiddler from the TiddlyWiki
echo "Deleting Tiddler: $TITLE"
2024-04-21 22:55:49 +02:00
tiddlywiki --load $TW \
2024-04-22 19:17:32 +02:00
--deletetiddlers "$TITLE" \
2024-04-21 22:55:49 +02:00
--output ~/.zen/tmp --render "$:/core/save/all" "${MOATS}.html" "text/plain"
2024-04-22 19:17:32 +02:00
# Check if deletion was successful
if [[ -s ~/.zen/tmp/${MOATS}.html ]]; then
echo "Tiddler deleted successfully."
cp ~/.zen/tmp/${MOATS}.html ${TW}
rm ~/.zen/tmp/${MOATS}.html
echo "Updated TiddlyWiki:
${TW}"
2024-04-22 19:17:32 +02:00
else
echo "ERROR: Cannot delete $TITLE from
$TW"
2024-04-22 19:17:32 +02:00
exit 1
fi
2024-04-21 22:55:49 +02:00
exit 0