⎗ ✓ 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 28 29 30 31 32 33 34 35 36#!/usr/bin/env bash MIN_VERSION=3.10 function version_gte() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } function usage() { echo "Usage: $(basename $0) <venv-name> [...]" echo "" exit 1 } VENV_NAME="$1" PYTHON="$(which python python3.10 python3.11 python3 2> /dev/null | tail -n 1)" if [ -n "$PYTHON" ]; then PYTHON_VER="$($PYTHON --version | cut -f2 -d' ')" echo "System python version $PYTHON_VER at $PYTHON" else PYTHON_VER=0 echo "No system python version found" fi : ${1?"$(usage)"} # Script exits here if command-line parameters absent if version_gte "$MIN_VERSION" "$PYTHON_VER"; then echo "Min python version $MIN_VERSION. TODO: pyenv" exit 1 else if [ ! -e $VENV_NAME ]; then $PYTHON -m venv "$VENV_NAME" fi bash --init-file <(echo "source ~/.bashrc; source ./$VENV_NAME/bin/activate") fi