Merge pull request #728 from Spatterjaaay/terminals

avoid expanding arguments into quoted strings
This commit is contained in:
Jesse Plamondon-Willard 2020-07-29 22:12:23 -04:00 committed by GitHub
commit 778bcdfbe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 46 deletions

View File

@ -46,80 +46,63 @@ else
if [ "$ARCH" == "x86_64" ]; then if [ "$ARCH" == "x86_64" ]; then
ln -sf mcs.bin.x86_64 mcs ln -sf mcs.bin.x86_64 mcs
cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64 cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64
LAUNCHER="./StardewModdingAPI.bin.x86_64 $*" LAUNCHER="./StardewModdingAPI.bin.x86_64"
else else
ln -sf mcs.bin.x86 mcs ln -sf mcs.bin.x86 mcs
cp StardewValley.bin.x86 StardewModdingAPI.bin.x86 cp StardewValley.bin.x86 StardewModdingAPI.bin.x86
LAUNCHER="./StardewModdingAPI.bin.x86 $*" LAUNCHER="./StardewModdingAPI.bin.x86"
fi fi
export LAUNCHER
# get cross-distro version of POSIX command # get cross-distro version of POSIX command
COMMAND="" COMMAND=""
if command -v command 2>/dev/null; then if command -v command 2>/dev/null; then
COMMAND="command -v" COMMAND="command -v"
elif type type 2>/dev/null; then elif type type 2>/dev/null; then
COMMAND="type" COMMAND="type -p"
fi fi
# select terminal (prefer xterm for best compatibility, then known supported terminals) # select terminal (prefer xterm for best compatibility, then known supported terminals)
for terminal in xterm gnome-terminal kitty terminator xfce4-terminal konsole terminal termite alacritty mate-terminal x-terminal-emulator; do for terminal in xterm gnome-terminal kitty terminator xfce4-terminal konsole terminal termite alacritty mate-terminal x-terminal-emulator; do
if $COMMAND "$terminal" 2>/dev/null; then if $COMMAND "$terminal" 2>/dev/null; then
# Find the true shell behind x-terminal-emulator export LAUNCHTERM=$terminal
if [ "$(basename "$(readlink -f $(which "$terminal"))")" != "x-terminal-emulator" ]; then break;
export LAUNCHTERM=$terminal
break;
else
export LAUNCHTERM="$(basename "$(readlink -f $(which x-terminal-emulator))")"
# Remember that we're using x-terminal-emulator just in case it points outside the $PATH
export XTE=1
break;
fi
fi fi
done done
# Find the true shell behind x-terminal-emulator
# if no terminal was found, run in current shell or with no output if [ "$LAUNCHTERM" = "x-terminal-emulator" ]; then
if [ -z "$LAUNCHTERM" ]; then export LAUNCHTERM="$(basename "$(readlink -f $(COMMAND x-terminal-emulator))")"
sh -c "TERM=xterm $LAUNCHER"
if [ $? -eq 127 ]; then
$LAUNCHER --no-terminal
fi
exit
fi fi
# run in selected terminal and account for quirks # run in selected terminal and account for quirks
case $LAUNCHTERM in case $LAUNCHTERM in
terminator) terminal|termite)
# Terminator converts -e to -x when used through x-terminal-emulator for some reason # LAUNCHTERM consumes only one argument after -e
if $XTE; then # options containing space characters are unsupported
terminator -e "sh -c 'TERM=xterm $LAUNCHER'" exec $LAUNCHTERM -e "env TERM=xterm $LAUNCHER $@"
else ;;
terminator -x "sh -c 'TERM=xterm $LAUNCHER'" xterm|konsole|alacritty)
fi # LAUNCHTERM consumes all arguments after -e
exec $LAUNCHTERM -e env TERM=xterm $LAUNCHER "$@"
;;
terminator|xfce4-terminal|mate-terminal)
# LAUNCHTERM consumes all arguments after -x
exec $LAUNCHTERM -x env TERM=xterm $LAUNCHER "$@"
;;
gnome-terminal)
# LAUNCHTERM consumes all arguments after --
exec $LAUNCHTERM -- env TERM=xterm $LAUNCHER "$@"
;; ;;
kitty) kitty)
# Kitty overrides the TERM varible unless you set it explicitly # LAUNCHTERM consumes all trailing arguments
kitty -o term=xterm $LAUNCHER exec $LAUNCHTERM env TERM=xterm $LAUNCHER "$@"
;;
alacritty)
# Alacritty doesn't like the double quotes or the variable
if [ "$ARCH" == "x86_64" ]; then
alacritty -e sh -c 'TERM=xterm ./StardewModdingAPI.bin.x86_64 $*'
else
alacritty -e sh -c 'TERM=xterm ./StardewModdingAPI.bin.x86 $*'
fi
;;
xterm|xfce4-terminal|gnome-terminal|terminal|termite|mate-terminal)
$LAUNCHTERM -e "sh -c 'TERM=xterm $LAUNCHER'"
;;
konsole)
konsole -p Environment=TERM=xterm -e "$LAUNCHER"
;; ;;
*) *)
# If we don't know the terminal, just try to run it in the current shell. # If we don't know the terminal, just try to run it in the current shell.
sh -c "TERM=xterm $LAUNCHER" env TERM=xterm $LAUNCHER "$@"
# if THAT fails, launch with no output # if THAT fails, launch with no output
if [ $? -eq 127 ]; then if [ $? -eq 127 ]; then
$LAUNCHER --no-terminal exec $LAUNCHER --no-terminal "$@"
fi fi
esac esac
fi fi