Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions Assets/EmuHawkMono.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,58 @@
#!/bin/sh
cd "$(dirname "$(realpath "$0")")"
libpath=""

case "$0" in
*"EmuHawkMono.sh");;
*"/bin/"*"sh")
# Very bad way to detect /path/to/shell
echo "I don't know where I am! Could you run me as \"/path/to/EmuHawkMono.sh\"?"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should support being renamed via symlinking.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this now support something like ln -s /opt/bizhawk/EmuHawkMono.sh ~/.local/bin/emuhawk?

Copy link
Copy Markdown
Author

@cD1rtX3 cD1rtX3 Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It will just think you're running it with a shell if that executable's name ends in sh, but not .sh, and it is in a folder called bin. I don't know how else to better detect a shell, since bash for some reason uses its fullly-qualified path as "$0" when a script is sourced.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's what this is for. I'm not sure I want to merge a hack just to detect a niche user error.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's fair. You could remove the hacky part, though you should probably keep the non-hacky part.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any updates?

# stupid bash workaround
# shellcheck disable=SC2317
return 1 2> /dev/null || exit 1;;
*"/"*);;
*)
echo "I don't know where I am! Could you run me as \"/path/to/EmuHawkMono.sh\"?"
# shellcheck disable=SC2317
return 1 2> /dev/null || exit 1
esac
cd "$(dirname -- "$(realpath -- "$0")")" || ( echo "Can't navigate to \$0's path?" >& 2; exit 1 )

libpath=
if [ "$(command -v lsb_release)" ]; then
# shellcheck disable=SC2018,SC2019
case "$(lsb_release -i | head -n1 | cut -c17- | tr A-Z a-z)" in
"arch"|"artix"|"manjarolinux") libpath="/usr/lib";;
"fedora"|"gentoo"|"nobaralinux"|"opensuse") libpath="/usr/lib64";;
"nixos") libpath="/usr/lib"; printf "Running on NixOS? Why aren't you using the Nix expr?\n";;
"nixos") libpath="/usr/lib"; echo "Running on NixOS? Why aren't you using the Nix expr?" >& 2;;
Comment thread
cD1rtX3 marked this conversation as resolved.
"debian"|"linuxmint"|"pop"|"ubuntu") libpath="/usr/lib/x86_64-linux-gnu";;
esac
else
printf "Distro does not provide LSB release info API! (You've met with a terrible fate, haven't you?)\n"
echo "Distro does not provide LSB release info API! (You've met with a terrible fate, haven't you?)" >& 2
fi
if [ -z "$libpath" ]; then
printf "%s\n" "Unknown distro, assuming system-wide libraries are in /usr/lib..."
echo "Unknown distro, assuming system-wide libraries are in /usr/lib..." >& 2
libpath="/usr/lib"
fi

export GTK_DATA_PREFIX=
Comment thread
cD1rtX3 marked this conversation as resolved.
Outdated
export LD_LIBRARY_PATH="$PWD/dll:$PWD:$libpath"
export MONO_CRASH_NOFILE=1
export MONO_WINFORMS_XIM_STYLE=disabled # see https://bugzilla.xamarin.com/show_bug.cgi?id=28047#c9

if [ "$1" = "--mono-no-redirect" ]; then
# printf "(passing --mono-no-redirect is no longer necessary)\n" #TODO uncomment later
echo "(passing --mono-no-redirect is no longer necessary)" >& 2
shift
fi
# shellcheck disable=SC2009
if (ps -C "mono" -o "cmd" --no-headers | grep -Fq "EmuHawk.exe"); then
printf "(it seems EmuHawk is already running, NOT capturing output)\n" >&2
exec mono EmuHawk.exe "$@"
echo "(it seems EmuHawk is already running, NOT capturing output)" >& 2
mono EmuHawk.exe "$@"
return 0
Comment thread
YoshiRulz marked this conversation as resolved.
Outdated
fi

o="$(mktemp -u)"
e="$(mktemp -u)"
mkfifo "$o" "$e"
printf "(capturing output in %s/EmuHawkMono_last*.txt)\n" "$PWD" >&2
tee EmuHawkMono_laststdout.txt <"$o" &
tee EmuHawkMono_laststderr.txt <"$e" | sed "s/.*/$(tput setaf 1)&$(tput sgr0)/" >&2 &
exec mono EmuHawk.exe "$@" >"$o" 2>"$e"
echo "(capturing output in $PWD/EmuHawkMono_last*.txt)" >& 2
tee EmuHawkMono_laststdout.txt < "$o" &
tee EmuHawkMono_laststderr.txt < "$e" | sed "s/.*/$(tput setaf 1)&$(tput sgr0)/" >& 2 &
mono EmuHawk.exe "$@" > "$o" 2> "$e"