Allow passing text input as a non-option argument

This commit is contained in:
Andrew S. Rightenburg 2023-09-25 21:24:27 +08:00
parent bb9a3e4565
commit 18bb7b98a7
Signed by: rail5
GPG Key ID: A0CB570AB6629159
2 changed files with 12 additions and 2 deletions

View File

@ -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.

View File

@ -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"