#!/usr/bin/env sh set -eu REPO_URL="${GETSUBTITLE_REPO_URL:-https://github.com/fpenguin/getsubtitle.git}" APP_HOME="${GETSUBTITLE_HOME:-$HOME/.local/share/getsubtitle}" BIN_DIR="${GETSUBTITLE_BIN_DIR:-$HOME/.local/bin}" APP_VENV="$APP_HOME/.venv" say() { printf '%s\n' "$*" } ask() { prompt="$1" default="$2" if [ ! -t 0 ]; then printf '%s\n' "$default" return fi printf '%s [%s] ' "$prompt" "$default" >&2 read -r answer || answer="" if [ -z "$answer" ]; then printf '%s\n' "$default" else printf '%s\n' "$answer" fi } find_python() { if [ "${PYTHON:-}" ]; then printf '%s\n' "$PYTHON" return fi for candidate in python3.13 python3.12 python3.11 python3.10 python3; do if command -v "$candidate" >/dev/null 2>&1; then printf '%s\n' "$candidate" return fi done } validate_python() { "$1" - <<'PY' import sys if sys.version_info < (3, 10): print(f"Python 3.10 or newer is required; found {sys.version.split()[0]}.") print("macOS Homebrew: brew install python@3.11") print("Then rerun: PYTHON=python3.11 sh setup.sh") raise SystemExit(1) PY } choose_extras() { if [ "${GETSUBTITLE_EXTRAS:-}" ]; then printf '%s\n' "$GETSUBTITLE_EXTRAS" return fi say "" say "Install optional reading-aid backends?" say " 1) All CJK helpers: Japanese furigana + Korean romanization + Mandarin pinyin + Cantonese Jyutping" say " 2) Japanese furigana only" say " 3) Korean romanization only" say " 4) Mandarin pinyin only" say " 5) Cantonese Jyutping only" say " 6) Minimal install" choice="$(ask "Choose 1/2/3/4/5/6" "1")" case "$choice" in 1|"") printf '%s\n' "furigana,romanization-ko,romanization-zh,romanization-yue" ;; 2) printf '%s\n' "furigana" ;; 3) printf '%s\n' "romanization-ko" ;; 4) printf '%s\n' "romanization-zh" ;; 5) printf '%s\n' "romanization-yue" ;; 6) printf '%s\n' "" ;; *) say "Unknown choice: $choice" say "Using all CJK helpers." printf '%s\n' "furigana,romanization-ko,romanization-zh,romanization-yue" ;; esac } install_spec_for_git() { extras="$1" if [ -n "$extras" ]; then printf '%s\n' "getsubtitle[$extras] @ git+$REPO_URL" else printf '%s\n' "getsubtitle @ git+$REPO_URL" fi } write_shim() { mkdir -p "$BIN_DIR" cat > "$BIN_DIR/getsubtitle" <