Skip to content

Instantly share code, notes, and snippets.

@sebastian-berlin-wmse
Last active May 30, 2024 15:18
Show Gist options
  • Save sebastian-berlin-wmse/faeb53ded902f0e37bbf4027a3484618 to your computer and use it in GitHub Desktop.
Save sebastian-berlin-wmse/faeb53ded902f0e37bbf4027a3484618 to your computer and use it in GitHub Desktop.
Setup and run venv
#! /usr/bin/env bash
# Add the following to .bashrc to make this work:
# alias venv=". venv"
source .venv/bin/activate && return 0
read -p "Create venv in .venv/? [y/N] " -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
pythonVersions=$(
ls ${PATH//:/ } |
grep -E "^python[0-9]+\.[0-9]+$" |
# Latest version at the top.
sort -V -r |
uniq
)
select pythonVersion in $pythonVersions
do
$pythonVersion -m venv .venv && source .venv/bin/activate
break
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment