Last active
May 17, 2025 20:37
-
-
Save SkyyySi/d16df4828e93bcda49fbebe03bc67815 to your computer and use it in GitHub Desktop.
A small bash script to rebuild and rerun a mod for Zelda 64: Recompiled whenever a change is made to a C source file
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
#!/usr/bin/env bash | |
# Zero-Clause BSD | |
# ============= | |
# | |
# Permission to use, copy, modify, and/or distribute this software for | |
# any purpose with or without fee is hereby granted. | |
# | |
# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL | |
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | |
# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE | |
# FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY | |
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN | |
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
set -uCo pipefail | |
cd "$(dirname -- "${BASH_SOURCE[0]}")" || exit 1 | |
function stop_game() { | |
printf '\n>>> Stopping currently running game instance(s)...\n' 1>&2 | |
killall \ | |
--exact \ | |
--quiet \ | |
--signal='KILL' \ | |
-- \ | |
'Zelda64Recompiled' | |
} | |
function handle_sigint() { | |
stop_game | |
exit 0 | |
} | |
# Stop the game when stopping this script via CTRL+C | |
trap handle_sigint SIGINT | |
declare changed_file='' | |
declare -i exit_code=0 | |
while true; do | |
clear | |
{ | |
make -j "$(nproc)" && | |
RecompModTool './mod.toml' './build' && | |
flatpak run \ | |
--command='/app/bin/Zelda64Recompiled' \ | |
'io.github.zelda64recomp.zelda64recomp' | |
} & | |
printf '>>> Waiting for changes to source files...\n' 1>&2 | |
while true; do | |
changed_file=$(inotifywait \ | |
--quiet \ | |
--recursive \ | |
--format='%w%f' \ | |
--event='modify' \ | |
--include='\.[ch]$' \ | |
--timeout='1' \ | |
-- \ | |
'./src' | |
) | |
exit_code=$? | |
if (( exit_code == 0 )); then | |
printf '>>> File change detected: %q\n\n' "$changed_file" 1>&2 | |
stop_game | |
break | |
elif (( exit_code == 1 )); then | |
printf '>>> Failed to wait for source file changes!\n' 1>&2 | |
echo "$changed_file" | |
exit 1 | |
elif (( exit_code == 2 )); then | |
#printf '>>> Timeout reached, still waiting...\n' 1>&2 | |
continue | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is made with the following expectations:
inotifywait
(from theinotify-tools
package) installedmod.toml
)RecompModTool
in your$PATH
environment