| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/usr/bin/env bash
- # vls_python — stream Windows python.exe output in WSL
- # Usage:
- # vls_python script.py [args...]
- # vls_python -c "print('hi')"
- # vls_python -m module [args...]
- set -euo pipefail
- # Path to Windows python.exe, via WSL mount
- PY="/mnt/d/vls-trunk/env-win64/python27/python.exe"
- if [[ ! -x "$PY" && ! -f "$PY" ]]; then
- echo "Error: python.exe not found at: $PY" >&2
- exit 1
- fi
- if [[ $# -lt 1 ]]; then
- echo "Usage: $0 <script.py | -c cmd | -m module | other python flags> [args...]" >&2
- exit 1
- fi
- # If first arg is a python flag (e.g. -c/-m/-V), pass through directly.
- if [[ "$1" == -* ]]; then
- exec "$PY" -u "$@"
- fi
- # Otherwise treat first arg as a script path; convert to Windows if it exists in WSL.
- SCRIPT="$1"; shift
- if [[ -e "$SCRIPT" ]]; then
- SCRIPT_WIN="$(wslpath -w "$SCRIPT")"
- else
- # allow passing a Windows-style path directly
- SCRIPT_WIN="$SCRIPT"
- fi
- # Optional: convert any remaining args that are existing WSL paths if you set
- # VLS_PYTHON_CONVERT_ARGS=1 (WINPY_CONVERT_ARGS is still accepted).
- ARGS=()
- convert_flag="${VLS_PYTHON_CONVERT_ARGS:-${WINPY_CONVERT_ARGS:-0}}"
- if [[ "$convert_flag" == "1" ]]; then
- for a in "$@"; do
- if [[ -e "$a" ]]; then
- ARGS+=("$(wslpath -w "$a")")
- else
- ARGS+=("$a")
- fi
- done
- else
- ARGS=("$@")
- fi
- # -u = unbuffered for immediate streaming
- exec "$PY" -u "$SCRIPT_WIN" "${ARGS[@]}"
|