Files
hugo/prune-orphans.sh
T

27 lines
687 B
Bash
Executable File

#!/usr/bin/env bash
# Remove content/zettels/*.md whose org source in ~/Cloud/brain no longer exists.
# Dry run by default; pass --delete to actually remove files.
set -euo pipefail
brain=~/Cloud/brain
zet="$(cd "$(dirname "$0")" && pwd)/content/zettels"
count=0
for md in "$zet"/*.md; do
name=$(basename "$md" .md)
[[ $name == _index ]] && continue
if [[ ! -f "$brain/$name.org" ]]; then
echo "orphan: $md"
[[ ${1:-} == --delete ]] && rm "$md"
count=$((count + 1))
fi
done
if [[ $count -eq 0 ]]; then
echo "No orphans."
elif [[ ${1:-} != --delete ]]; then
echo "$count orphan(s). Re-run with --delete to remove them."
else
echo "Removed $count file(s)."
fi