Skip to content

Commit 98287a4

Browse files
authored
Update EmuHawkMono.sh
Added: * check against useless `"$0"`, * `export GTK_PREFIX=`, and * shellcheck directives against warnings; redirected status messages to `stderr`; and removed `exec`.
1 parent 3bfd5dd commit 98287a4

1 file changed

Lines changed: 34 additions & 12 deletions

File tree

Assets/EmuHawkMono.sh

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,57 @@
11
#!/bin/sh
2-
cd "$(dirname "$(realpath "$0")")"
3-
libpath=""
2+
3+
case "$0" in
4+
*"EmuHawkMono.sh");;
5+
*"/bin/"*"sh")
6+
# Very bad way to detect /path/to/shell
7+
echo "I don't know where I am! Could you run me as \"/path/to/EmuHawkMono.sh\"?"
8+
# stupid bash workaround
9+
# shellcheck disable=SC2317
10+
return 1 2> /dev/null || exit 1;;
11+
*"/"*);;
12+
*)
13+
echo "I don't know where I am! Could you run me as \"/path/to/EmuHawkMono.sh\"?"
14+
# shellcheck disable=SC2317
15+
return 1 2> /dev/null || exit 1
16+
esac
17+
cd "$(dirname -- "$(realpath -- "$0")")" || ( echo "Can't navigate to \$0's path?" >& 2; exit 1 )
18+
19+
libpath=
420
if [ "$(command -v lsb_release)" ]; then
21+
# shellcheck disable=SC2018,SC2019
522
case "$(lsb_release -i | head -n1 | cut -c17- | tr A-Z a-z)" in
623
"arch"|"artix"|"manjarolinux") libpath="/usr/lib";;
724
"fedora"|"gentoo"|"nobaralinux"|"opensuse") libpath="/usr/lib64";;
8-
"nixos") libpath="/usr/lib"; printf "Running on NixOS? Why aren't you using the Nix expr?\n";;
25+
"nixos") libpath="/usr/lib"; echo "Running on NixOS? Why aren't you using the Nix expr?" >& 2;;
926
"debian"|"linuxmint"|"pop"|"ubuntu") libpath="/usr/lib/x86_64-linux-gnu";;
1027
esac
1128
else
12-
printf "Distro does not provide LSB release info API! (You've met with a terrible fate, haven't you?)\n"
29+
echo "Distro does not provide LSB release info API! (You've met with a terrible fate, haven't you?)" >& 2
1330
fi
1431
if [ -z "$libpath" ]; then
15-
printf "%s\n" "Unknown distro, assuming system-wide libraries are in /usr/lib..."
32+
echo "Unknown distro, assuming system-wide libraries are in /usr/lib..." >& 2
1633
libpath="/usr/lib"
1734
fi
35+
36+
export GTK_DATA_PREFIX=
1837
export LD_LIBRARY_PATH="$PWD/dll:$PWD:$libpath"
1938
export MONO_CRASH_NOFILE=1
2039
export MONO_WINFORMS_XIM_STYLE=disabled # see https://bugzilla.xamarin.com/show_bug.cgi?id=28047#c9
40+
2141
if [ "$1" = "--mono-no-redirect" ]; then
22-
# printf "(passing --mono-no-redirect is no longer necessary)\n" #TODO uncomment later
42+
echo "(passing --mono-no-redirect is no longer necessary)" >& 2
2343
shift
2444
fi
45+
# shellcheck disable=SC2009
2546
if (ps -C "mono" -o "cmd" --no-headers | grep -Fq "EmuHawk.exe"); then
26-
printf "(it seems EmuHawk is already running, NOT capturing output)\n" >&2
27-
exec mono EmuHawk.exe "$@"
47+
echo "(it seems EmuHawk is already running, NOT capturing output)" >& 2
48+
mono EmuHawk.exe "$@"
2849
fi
50+
2951
o="$(mktemp -u)"
3052
e="$(mktemp -u)"
3153
mkfifo "$o" "$e"
32-
printf "(capturing output in %s/EmuHawkMono_last*.txt)\n" "$PWD" >&2
33-
tee EmuHawkMono_laststdout.txt <"$o" &
34-
tee EmuHawkMono_laststderr.txt <"$e" | sed "s/.*/$(tput setaf 1)&$(tput sgr0)/" >&2 &
35-
exec mono EmuHawk.exe "$@" >"$o" 2>"$e"
54+
echo "(capturing output in $PWD/EmuHawkMono_last*.txt)" >& 2
55+
tee EmuHawkMono_laststdout.txt < "$o" &
56+
tee EmuHawkMono_laststderr.txt < "$e" | sed "s/.*/$(tput setaf 1)&$(tput sgr0)/" >& 2 &
57+
mono EmuHawk.exe "$@" > "$o" 2> "$e"

0 commit comments

Comments
 (0)