diff options
Diffstat (limited to 'src/SMAPI.Installer/unix-launcher.sh')
-rw-r--r-- | src/SMAPI.Installer/unix-launcher.sh | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/src/SMAPI.Installer/unix-launcher.sh b/src/SMAPI.Installer/unix-launcher.sh index a98d527d..f81828f0 100644 --- a/src/SMAPI.Installer/unix-launcher.sh +++ b/src/SMAPI.Installer/unix-launcher.sh @@ -1,14 +1,14 @@ -#!/bin/bash +#!/usr/bin/env bash # MonoKickstart Shell Script # Written by Ethan "flibitijibibo" Lee -# Modified for StardewModdingAPI by Viz and Pathoschild +# Modified for SMAPI by various contributors # Move to script's directory -cd "`dirname "$0"`" +cd "$(dirname "$0")" || exit $? # Get the system architecture -UNAME=`uname` -ARCH=`uname -m` +UNAME=$(uname) +ARCH=$(uname -m) # MonoKickstart picks the right libfolder, so just execute the right binary. if [ "$UNAME" == "Darwin" ]; then @@ -39,18 +39,18 @@ if [ "$UNAME" == "Darwin" ]; then # launch SMAPI cp StardewValley.bin.osx StardewModdingAPI.bin.osx - open -a Terminal ./StardewModdingAPI.bin.osx $@ + open -a Terminal ./StardewModdingAPI.bin.osx "$@" else # choose launcher LAUNCHER="" if [ "$ARCH" == "x86_64" ]; then ln -sf mcs.bin.x86_64 mcs cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64 - LAUNCHER="./StardewModdingAPI.bin.x86_64 $@" + LAUNCHER="./StardewModdingAPI.bin.x86_64 $*" else ln -sf mcs.bin.x86 mcs cp StardewValley.bin.x86 StardewModdingAPI.bin.x86 - LAUNCHER="./StardewModdingAPI.bin.x86 $@" + LAUNCHER="./StardewModdingAPI.bin.x86 $*" fi # get cross-distro version of POSIX command @@ -61,37 +61,57 @@ else COMMAND="type" fi - # open SMAPI in terminal - if $COMMAND xterm 2>/dev/null; then - xterm -e "$LAUNCHER" - elif $COMMAND x-terminal-emulator 2>/dev/null; then - # Terminator converts -e to -x when used through x-terminal-emulator for some reason (per - # `man terminator`), which causes an "unable to find shell" error. If x-terminal-emulator - # is mapped to Terminator, invoke it directly instead. - if [[ "$(readlink -e $(which x-terminal-emulator))" == *"/terminator" ]]; then - terminator -e "sh -c 'TERM=xterm $LAUNCHER'" - else - x-terminal-emulator -e "sh -c 'TERM=xterm $LAUNCHER'" + # select terminal (prefer $TERMINAL for overrides and testing, then xterm for best compatibility, then known supported terminals) + for terminal in "$TERMINAL" xterm gnome-terminal kitty terminator xfce4-terminal konsole terminal termite x-terminal-emulator; do + if $COMMAND "$terminal" 2>/dev/null; then + # Find the true shell behind x-terminal-emulator + if [ "$(basename "$(readlink -f $(which "$terminal"))")" != "x-terminal-emulator" ]; then + 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 - elif $COMMAND xfce4-terminal 2>/dev/null; then - xfce4-terminal -e "sh -c 'TERM=xterm $LAUNCHER'" - elif $COMMAND gnome-terminal 2>/dev/null; then - gnome-terminal -e "sh -c 'TERM=xterm $LAUNCHER'" - elif $COMMAND konsole 2>/dev/null; then - konsole -p Environment=TERM=xterm -e "$LAUNCHER" - elif $COMMAND terminal 2>/dev/null; then - terminal -e "sh -c 'TERM=xterm $LAUNCHER'" - elif $COMMAND termite 2>/dev/null; then - termite -e "sh -c 'TERM=xterm $LAUNCHER'" - else + done + + # if no terminal was found, run in current shell or with no output + if [ -z "$LAUNCHTERM" ]; then sh -c 'TERM=xterm $LAUNCHER' + if [ $? -eq 127 ]; then + $LAUNCHER --no-terminal + fi + exit fi - # some Linux users get error 127 (command not found) from the above block, even though - # `command -v` indicates the command is valid. As a fallback, launch SMAPI without a terminal when - # that happens and pass in an argument indicating SMAPI shouldn't try writing to the terminal - # (which can be slow if there is none). - if [ $? -eq 127 ]; then - $LAUNCHER --no-terminal - fi + # run in selected terminal and account for quirks + case $LAUNCHTERM in + terminator) + # Terminator converts -e to -x when used through x-terminal-emulator for some reason + if $XTE; then + terminator -e "sh -c 'TERM=xterm $LAUNCHER'" + else + terminator -x "sh -c 'TERM=xterm $LAUNCHER'" + fi + ;; + kitty) + # Kitty overrides the TERM varible unless you set it explicitly + kitty -o term=xterm $LAUNCHER + ;; + xterm|xfce4-terminal|gnome-terminal|terminal|termite) + $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. + sh -c 'TERM=xterm $LAUNCHER' + # if THAT fails, launch with no output + if [ $? -eq 127 ]; then + $LAUNCHER --no-terminal + fi + esac fi |