Created
February 1, 2026 07:06
-
-
Save yancya/85c5ec1b587feb42a3e1a537e719d01d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
List の時点で hash が貰えてないなら、hash で比較する意味なさそう