summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md3
-rw-r--r--docs/technical/smapi.md10
-rw-r--r--src/SMAPI.Installer/assets/unix-launcher.sh61
3 files changed, 47 insertions, 27 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index d92ef63d..3030cc5d 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -5,6 +5,9 @@
* For players:
* Improved translations. Thanks to ChulkyBow (updated Ukrainian)!
* Fixed `player_add` console command's handling of Journal Scraps and Secret Notes.
+ * Improved [command-line arguments](technical/smapi.md#command-line-arguments) on Linux/macOS:
+ * Added `--use-current-shell` to avoid opening a separate terminal window.
+ * Fixed `--no-terminal` still opening a terminal window, even if nothing is logged to it (thanks to Ryhon0!).
* For mod authors:
* Overhauled [mod-provided APIs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Integrations#Mod-provided_APIs) (thanks to Shockah!).
diff --git a/docs/technical/smapi.md b/docs/technical/smapi.md
index d9aad875..7da1e0f1 100644
--- a/docs/technical/smapi.md
+++ b/docs/technical/smapi.md
@@ -38,18 +38,20 @@ or testing and may change without warning. On Linux/macOS, see _environment vari
argument | purpose
-------- | -------
-`--no-terminal` | SMAPI won't write anything to the console window. (Messages will still be written to the log file.)
+`--no-terminal` | The SMAPI launcher won't try to open a terminal window, and SMAPI won't log anything to the console. (Messages will still be written to the log file.)
+`--use-current-shell` | The SMAPI launcher won't try to open a terminal window, but SMAPI will still log to the console. (Messages will still be written to the log file.)
`--mods-path` | The path to search for mods, if not the standard `Mods` folder. This can be a path relative to the game folder (like `--mods-path "Mods (test)"`) or an absolute path.
### Environment variables
-The above SMAPI arguments don't work on Linux/macOS due to the way the game launcher works. You can
-set temporary environment variables instead. For example:
+The above SMAPI arguments may not work on Linux/macOS due to the way the game launcher works. You
+can set temporary environment variables instead. For example:
> SMAPI_MODS_PATH="Mods (multiplayer)" /path/to/StardewValley
environment variable | purpose
-------------------- | -------
-`SMAPI_NO_TERMINAL` | Equivalent to `--no-terminal` above.
`SMAPI_MODS_PATH` | Equivalent to `--mods-path` above.
+`SMAPI_NO_TERMINAL` | Equivalent to `--no-terminal` above.
+`SMAPI_USE_CURRENT_SHELL` | Equivalent to `--use-current-shell` above.
### Compile flags
SMAPI uses a small number of conditional compilation constants, which you can set by editing the
diff --git a/src/SMAPI.Installer/assets/unix-launcher.sh b/src/SMAPI.Installer/assets/unix-launcher.sh
index 6e8d4df3..ae9624e7 100644
--- a/src/SMAPI.Installer/assets/unix-launcher.sh
+++ b/src/SMAPI.Installer/assets/unix-launcher.sh
@@ -6,19 +6,40 @@
# move to script's directory
cd "$(dirname "$0")" || exit $?
-# change to true to skip opening a terminal
+# Whether to avoid opening a separate terminal window, and avoid logging anything to the console.
# This isn't recommended since you won't see errors, warnings, and update alerts.
-OPTS=`getopt -o St --long skip-terminal,terminal -n 'parse-options' -- "$@"`
-while true; do
- case "$1" in
- -S | --skip-terminal ) SKIP_TERMINAL=true; shift ;;
- -t | --terminal ) SKIP_TERMINAL=false; shift ;;
- -- ) shift; break ;;
- * ) break ;;
- esac
+SKIP_TERMINAL=false
+
+# Whether to avoid opening a separate terminal, but still send the usual log output to the console.
+USE_CURRENT_SHELL=false
+
+
+##########
+## Read environment variables
+##########
+if [ "$SMAPI_NO_TERMINAL" == "true" ]; then
+ SKIP_TERMINAL=true
+fi
+if [ "$SMAPI_USE_CURRENT_SHELL" == "true" ]; then
+ USE_CURRENT_SHELL=true
+fi
+
+
+##########
+## Read command-line arguments
+##########
+while [ "$#" -gt 0 ]; do
+ case "$1" in
+ --skip-terminal ) SKIP_TERMINAL=true; shift ;;
+ --use-current-shell ) USE_CURRENT_SHELL=true; shift ;;
+ -- ) shift; break ;;
+ * ) shift ;;
+ esac
done
-${SKIP_TERMINAL:=false}
+if [ "$SKIP_TERMINAL" == "true" ]; then
+ USE_CURRENT_SHELL=true
+fi
##########
@@ -28,21 +49,13 @@ ${SKIP_TERMINAL:=false}
# Besides letting the player see errors/warnings/alerts in the console, this is also needed because
# Steam messes with the PATH.
if [ "$(uname)" == "Darwin" ]; then
- if [ ! -t 1 ]; then # https://stackoverflow.com/q/911168/262123
- # sanity check to make sure we don't have an infinite loop of opening windows
- for argument in "$@"; do
- if [ "$argument" == "--no-reopen-terminal" ]; then
- SKIP_TERMINAL=true
- break
- fi
- done
-
+ if [ ! -t 1 ]; then # not open in Terminal (https://stackoverflow.com/q/911168/262123)
# reopen in Terminal if needed
# https://stackoverflow.com/a/29511052/262123
- if [ "$SKIP_TERMINAL" == "false" ]; then
+ if [ "$USE_CURRENT_SHELL" == "false" ]; then
echo "Reopening in the Terminal app..."
echo '#!/bin/sh' > /tmp/open-smapi-terminal.sh
- echo "\"$0\" $@ --no-reopen-terminal" >> /tmp/open-smapi-terminal.sh
+ echo "\"$0\" $@ --use-current-shell" >> /tmp/open-smapi-terminal.sh
chmod +x /tmp/open-smapi-terminal.sh
cat /tmp/open-smapi-terminal.sh
open -W -a Terminal /tmp/open-smapi-terminal.sh
@@ -78,7 +91,7 @@ else
export LAUNCH_FILE
# run in terminal
- if [ "$SKIP_TERMINAL" == "false" ]; then
+ if [ "$USE_CURRENT_SHELL" == "false" ]; then
# 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
if command -v "$terminal" 2>/dev/null; then
@@ -141,7 +154,9 @@ else
fi
# explicitly run without terminal
- else
+ elif [ "$SKIP_TERMINAL" == "true" ]; then
exec $LAUNCH_FILE --no-terminal "$@"
+ else
+ exec $LAUNCH_FILE "$@"
fi
fi