all repos — dot @ 3cfe984ab7e26aaad4a2442501526b6a2f232bc0

Shell, editor and terminal configuration, and the tools that go with them

bin/pyexec (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
#!/bin/bash

set -euo pipefail

debug() {
  if [[ "${DEBUG:-}" == "pyexec" ]]; then
    >&2 echo "[DEBUG=pyexec]" "$@"
  fi
}

if [[ -n "${VIRTUAL_ENV:-}" ]]; then
  debug "Detected VIRTUAL_ENV"
  i=python
elif [[ -r ".venv/bin/activate" ]]; then
  debug "Found .venv, activating"
  source .venv/bin/activate
  i=python
elif command -v python3 >/dev/null; then
  debug "Found python3 in path"
  i=python3
else
  debug "Defaulting to python"
  i=python
fi

exec "$i" "$@"