# POSIX sh / Dash Integration To make interacting with the STT (Speech-to-Text) CLI easier, you can add a shortcut function to your shell profile. This allows you to simply type `s "your question"` in the terminal. > **Note:** Dash and other strict POSIX shells (`/bin/sh` on Debian/Ubuntu is Dash by default) do **not** support the `local` keyword in all contexts, process substitution, or arrays. The function below is written to be fully POSIX-compatible. ## Setup Instructions 1. Open your shell profile with an editor you like: ```sh nano ~/.profile # or, if your system uses ~/.shrc for interactive shells: nano ~/.shrc ``` 2. Paste the following block at the end of the file: ```sh please read newest updates in zsh - verson # --- STT Project Path Resolution --- unalias s 2>/dev/null s() { if [ $# -eq 0 ]; then echo "question " return 1 fi update_github_ip TEMP_FILE=$(mktemp) SHORT_TIMEOUT_SECONDS=2 LONG_TIMEOUT_SECONDS=70 # Path shortcuts PY_EXEC="$SL5NET_AURA_PROJECT_ROOT/.venv/bin/python3" CLI_SCRIPT="$SL5NET_AURA_PROJECT_ROOT/scripts/py/cli_client.py" # --- 1. try timeout "$SHORT_TIMEOUT_SECONDS" \ "$PY_EXEC" -u "$CLI_SCRIPT" "$@" \ --lang "de-DE" --unmasked < /dev/null > "$TEMP_FILE" 2>&1 EXIT_CODE=$? OUTPUT=$(cat "$TEMP_FILE") rm "$TEMP_FILE" if echo "$OUTPUT" | grep -q "Verbindungsfehler" || ! pgrep -f "streamlit-chat.py" > /dev/null; then echo "Service-Check: Backend oder Frontend fehlt. Starte neu..." start_service echo '++++++++++++++++++++++++++++++++++++++++++++++++++' KIWIX_SCRIPT="$SL5NET_AURA_PROJECT_ROOT/config/maps/plugins/standard_actions/wikipedia_local/de-DE/kiwix-docker-start-if-not-running.sh" if [ -f "$KIWIX_SCRIPT" ]; then sh "$KIWIX_SCRIPT" fi echo '++++++++++++++++++++++++++++++++++++++++++++++++++' echo "BITTE ERNEUT EINGEBEN: s $*" return 1 # 2. Timeout (124) OR success (0) elif [ "$EXIT_CODE" -eq 124 ] || [ "$EXIT_CODE" -eq 0 ]; then if [ "$EXIT_CODE" -eq 0 ]; then echo "$OUTPUT" return 0 fi echo "answer > $SHORT_TIMEOUT_SECONDS sec. set Timeout= $LONG_TIMEOUT_SECONDS s..." TEMP_FILE_2=$(mktemp) timeout "$LONG_TIMEOUT_SECONDS" \ "$PY_EXEC" -u "$CLI_SCRIPT" "$@" \ --lang "de-DE" --unmasked < /dev/null > "$TEMP_FILE_2" 2>&1 EXIT_CODE_2=$? OUTPUT_2=$(cat "$TEMP_FILE_2") rm "$TEMP_FILE_2" echo "$OUTPUT_2" if [ "$EXIT_CODE_2" -ne 0 ]; then echo "WARNUNG: Timeout > $LONG_TIMEOUT_SECONDS Sec. " fi return 0 else echo "ERROR" echo "$OUTPUT" return $EXIT_CODE fi } ``` 3. Reload your configuration: ```sh . ~/.profile ``` ## POSIX / Dash-Specific Notes - `local` is **not** used here for maximum compatibility. All variables are function-scoped by convention only; they are technically global in strict POSIX sh. - `$@` is preferred over `$*` when passing arguments to commands, to preserve proper word splitting with quoted arguments. - `bash` is replaced with `sh` when executing the Kiwix helper script to stay within the POSIX toolchain. - This configuration file is best placed in `~/.profile`, which is sourced by login shells. For interactive non-login shells, your distribution may use `~/.shrc` — check your system documentation. ## Features - **Dynamic Paths**: Automatically finds the project root via the `/tmp` marker file. - **Auto-Restart**: If the backend is down, it attempts to run `start_service` and local Wikipedia services. - **Smart Timeouts**: Tries a quick 2-second response first, then falls back to a 70-second deep processing mode.