From 57f6b18abe285383d5c98dc2bd7eda3d8c2672c7 Mon Sep 17 00:00:00 2001 From: Stefan Gaiselmann Date: Thu, 2 Feb 2023 11:48:26 +0100 Subject: [PATCH] Added python virtualenv helper functions. --- dot_bashrc.d/executable_09.functions.tmpl | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dot_bashrc.d/executable_09.functions.tmpl b/dot_bashrc.d/executable_09.functions.tmpl index 77796a5..ff88c90 100755 --- a/dot_bashrc.d/executable_09.functions.tmpl +++ b/dot_bashrc.d/executable_09.functions.tmpl @@ -159,4 +159,31 @@ dcupdate() { # TODO: logfile } +# Python virtualenv helper +function activate-venv() { + local venv=${1:-noneselected} + local ENV_DIR=$HOME/.virtual_envs + + if [[ -d "$ENV_DIR/$venv" ]]; then + echo -e "\e[32msetting virtualenv to $ENV_DIR/$venv \e[0m" + source "$ENV_DIR/$venv/bin/activate" + else + echo -e "\e[33mvirtualenv does not exist\e[0m" + echo -e "Current virtualenvs available: \e[32m" + ls "$ENV_DIR" + echo -e "\e[0m" + fi +} +function create-venv() { + local venv=$1 + local ENV_DIR=$HOME/.virtual_envs + + if [[ "$venv" =~ ^[a-zA-Z0-9_-]+$ ]]; then + python3 -m venv "$ENV_DIR/$venv" + echo -e "\e[32mvirtualenv created: $ENV_DIR/$venv \e[0m" + else + echo -e "\e[32minvalid name: $venv \e[0m" + fi +} + PATH=$PATH:$HOME/bin