diff --git a/prune-orphans.sh b/prune-orphans.sh new file mode 100755 index 0000000..b5562fa --- /dev/null +++ b/prune-orphans.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Remove content/
/*.md (zettels and bibliography) 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 +content="$(cd "$(dirname "$0")" && pwd)/content" +sections=(zettels book phdthesis inbook techreport article inproceedings websites) + +count=0 +for section in "${sections[@]}"; do + for md in "$content/$section"/*.md; do + [[ -e $md ]] || continue + 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 +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