From 18bb7b98a7bb7b680419c266655cb7b7378a987b Mon Sep 17 00:00:00 2001 From: rail5 Date: Mon, 25 Sep 2023 21:24:27 +0800 Subject: [PATCH] Allow passing text input as a non-option argument --- README.md | 6 +++++- stranslate | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d8c3e4f..34aba2b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,11 @@ SimplyTranslate can use both Google Translate and LibreTranslate, without compro ## Usage -Basic usage: `stranslate -f "Chinese" -t "English" -i "你好"` +Basic usage: + +`stranslate -f "Chinese" -t "English" -i "你好"` + +`stranslate "你好"` For detailed information about the usage of the program, see the manual. diff --git a/stranslate b/stranslate index e62f5dc..caa7608 100755 --- a/stranslate +++ b/stranslate @@ -161,7 +161,13 @@ do esac done -[ -z "${input}" ] && echo "An input is needed. Please use the -i option." && exit 2 +# Allow passing text to translate without -i +if [ -z "${input}" ]; then + shift $(($OPTIND-1)) + input="$1" +fi + +[ -z "${input}" ] && echo "stranslate: No input provided" && exit 2 [ -z "${from_language}" ] && from_language="Autodetect" [ -z "${to_language}" ] && to_language="English"