#!/usr/bin/env bash THREADS_DB="${HOME}/Library/Application Support/Zed/threads/threads.db" if ! command -v sqlite3 &> /dev/null; then echo "Error: sqlite3 is not installed. Please install SQLite to continue." exit 1 fi if ! command -v duckdb &> /dev/null; then echo "Error: duckdb is not installed. Please install DuckDB to continue." exit 1 fi if ! command -v zstd &> /dev/null; then echo "Error: zstd is not installed. Please install zstd to continue." exit 1 fi if [ ! -f "${THREADS_DB}" ]; then echo "Error: Threads database not found at ${THREADS_DB}" echo "Make sure Zed is installed and has created the threads database." exit 1 fi rm -rf "$(pwd)/threads/" mkdir -p "$(pwd)/threads/"{0.1.0,0.2.0,0.3.0} cp "${THREADS_DB}" . sqlite3 threads.db "SELECT id FROM threads;" | \ while read id; do sqlite3 threads.db "SELECT writefile('temp_${id}.zst', data) FROM threads WHERE id = '$id';" > /dev/null zstd --rm -q -d "temp_${id}.zst" -o "$(pwd)/threads/${id}.json" > /dev/null [[ $(jq 'has("version") and .version == "0.1.0"' "$(pwd)/threads/${id}.json") == "true" ]] && mv "$(pwd)/threads/${id}.json" "$(pwd)/threads/0.1.0/${id}.json" && continue [[ $(jq 'has("version") and .version == "0.2.0"' "$(pwd)/threads/${id}.json") == "true" ]] && mv "$(pwd)/threads/${id}.json" "$(pwd)/threads/0.2.0/${id}.json" && continue [[ $(jq 'has("version") and .version == "0.3.0"' "$(pwd)/threads/${id}.json") == "true" ]] && mv "$(pwd)/threads/${id}.json" "$(pwd)/threads/0.3.0/${id}.json" done duckdb -csv <