Skip to content

Instantly share code, notes, and snippets.

@Zei33
Created June 18, 2025 04:43
Show Gist options
  • Save Zei33/f0f6a39c5e5d91ab72685621a6bef304 to your computer and use it in GitHub Desktop.
Save Zei33/f0f6a39c5e5d91ab72685621a6bef304 to your computer and use it in GitHub Desktop.
Godot CLI UID File Generation
#!/usr/bin/env zsh
# Add the following line to your ~/.zshrc or ~/.bashrc depending on OS.
# alias godot-uid='/Users/username/path/to/script/generate-uid.sh "$PWD"'
# Then make this script executable with chmod +x generate-uid.sh
# You can run this in your Godot project directory root to auto-generate missing .uid files.
# If using AI, add a Cursor rule (.cursor/rules/godot-uids.mdc) so your editor knows to use it.
# Provides a handy output of newly created files too!
set -e # bail on script errors
proj_dir="${1:-$PWD}" # default to current dir if no arg
echo "🔧 Starting UID generation in $proj_dir …"
# ---------- 1) snapshot BEFORE ----------
tmp_before=$(mktemp)
find "$proj_dir" -type f -name '*.uid' | sort > "$tmp_before"
# ---------- 2) run Godot ----------
godot_log=$(godot -e --headless --path "$proj_dir" --quit 2>&1)
rc=$?
if (( rc != 0 )); then
echo "❌ UID generation failed—full log below:" >&2
echo "$godot_log" >&2
rm -f "$tmp_before"
exit $rc
fi
# ---------- 3) snapshot AFTER & diff ----------
tmp_after=$(mktemp)
find "$proj_dir" -type f -name '*.uid' | sort > "$tmp_after"
new_files=$(comm -13 "$tmp_before" "$tmp_after") # only in AFTER set
rm -f "$tmp_before" "$tmp_after"
echo "✅ UIDs generated successfully."
if [[ -z $new_files ]]; then
echo "ℹ️ No new .uid files were created."
exit 0
fi
echo "🆕 New UID files:\
"
#echo "--------------------------------------------"
while IFS= read -r uid_file; do
rel_path="${uid_file#$proj_dir/}" # strip project prefix
printf '%s: ' "$rel_path"
cat "$uid_file"
done <<< "$new_files"
#echo "--------------------------------------------"
@Zei33
Copy link
Author

Zei33 commented Jun 18, 2025

Add the following line to your ~/.zshrc or ~/.bashrc depending on OS.

alias godot-uid='/Users/username/path/to/script/generate-uid.sh "$PWD"'

Then make this script executable with chmod +x generate-uid.sh

You can run godot-uid command in your Godot project directory root to auto-generate missing .uid files.
If using AI, add a Cursor rule (.cursor/rules/godot-uids.mdc) so your editor knows to use it.
Provides a handy output of newly created files too!

@Zei33
Copy link
Author

Zei33 commented Jun 18, 2025

Note: On MacOS you need to have created a symlink to your Godot executable like doing a command like this

sudo ln -s "/Users/username/path/to/Godot_mono.app/Contents/MacOS/Godot" /usr/local/bin/godot

Otherwise the godot command line won't be available. Linux should automatically have this as godot or godot4 (you'll need to update the command in the above script to work with godot4 version).

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