Skip to content

Instantly share code, notes, and snippets.

@yancya
Created February 1, 2026 07:06
Show Gist options
  • Select an option

  • Save yancya/85c5ec1b587feb42a3e1a537e719d01d to your computer and use it in GitHub Desktop.

Select an option

Save yancya/85c5ec1b587feb42a3e1a537e719d01d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Gist ID
GIST_ID="${FARMER_WAS_REPLACED_GIST_ID}"
# Save0 ディレクトリのパス
SAVE_DIR="/Users/${USER}/Library/Application Support/com.TheFarmerWasReplaced.TheFarmerWasReplaced/Saves/Save0"
cd "$SAVE_DIR" || exit 1
echo "🚀 Syncing files to Gist..."
# Gistの現在のファイル情報を取得(サイズとraw_url)
GIST_DATA=$(gh api gists/$GIST_ID)
# __builtins__.py 以外の全ファイルを1つずつチェック
for file in *.py *.md; do
if [ ! -f "$file" ] || [ "$file" = "__builtins__.py" ]; then
continue
fi
# 空ファイルをスキップ
if [ ! -s "$file" ]; then
echo " ⏭️ $file (empty, skipped)"
continue
fi
# ローカルファイルのSHA256ハッシュを計算
LOCAL_HASH=$(shasum -a 256 "$file" | awk '{print $1}')
# Gist上のファイルサイズを取得
GIST_SIZE=$(echo "$GIST_DATA" | jq -r ".files[\"$file\"].size // 0")
LOCAL_SIZE=$(wc -c < "$file" | tr -d ' ')
# サイズが違えば確実に更新が必要
if [ "$GIST_SIZE" != "$LOCAL_SIZE" ]; then
echo " 📝 $file (size changed: $GIST_SIZE -> $LOCAL_SIZE)"
gh gist edit "$GIST_ID" --add "$file"
continue
fi
# サイズが同じ場合、ハッシュで比較
RAW_URL=$(echo "$GIST_DATA" | jq -r ".files[\"$file\"].raw_url // \"\"")
if [ -n "$RAW_URL" ]; then
GIST_HASH=$(curl -sL "$RAW_URL" | shasum -a 256 | awk '{print $1}')
if [ "$GIST_HASH" = "$LOCAL_HASH" ]; then
echo " ✓ $file (unchanged)"
continue
else
echo " 📝 $file (content changed)"
gh gist edit "$GIST_ID" --add "$file"
fi
else
# Gistに存在しない新規ファイル
echo " 📝 $file (new)"
gh gist edit "$GIST_ID" --add "$file"
fi
done
echo "✅ Done!"
@yancya
Copy link
Author

yancya commented Feb 1, 2026

List の時点で hash が貰えてないなら、hash で比較する意味なさそう

@yancya
Copy link
Author

yancya commented Feb 1, 2026

動いてるからいいが

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment