Last active
August 27, 2021 23:21
-
-
Save kota7/436eef582a801882e0c2100c35d50ae7 to your computer and use it in GitHub Desktop.
Add this to `.bashrc`, `.bash_profile` or alike to use `venv` in a similar manner as conda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# **************************************** | |
# VENV WRAPPER to use like conda | |
# add this to .bashrc or .bash_profile | |
# | |
# | |
# Create env: | |
# | |
# venvc <envname> | |
# | |
# Activate env: | |
# | |
# venva <envname> | |
# | |
# Deactivate env: | |
# | |
# venvd | |
# or | |
# deactivate | |
# | |
# Remove env: | |
# | |
# venvr <envname> | |
# or if error, | |
# venvr <envname> -f | |
# | |
# Show env list | |
# | |
# venvl | |
# ***************************************** | |
# choose the default venv location | |
VENVROOT="$HOME/venv" | |
function _venvc() { | |
# internally used by venv3 and venv2 | |
# $1 : env name | |
# $2 : python version | |
if [ -z "$1" ] | |
then | |
echo "Provide env name; e.g. venvc$2 <envname>" | |
else | |
python$2 -m venv "$VENVROOT/$1" && echo "Created env at $VENVROOT/$1" | |
fi | |
} | |
function venvc2() { _venvc "$1" 2; } | |
function venvc3() { _venvc "$1" 3; } | |
alias venvc=venvc3 | |
# because i use python3 most of the time | |
function venva() { source "$VENVROOT/$1/bin/activate"; } | |
alias venvd=deactivate | |
function venvr() { | |
# $1 : env name | |
# $2...: options to rm, in case -f or sort is needed | |
envname="$1" | |
shift | |
if [ -z "$envname" ] | |
then | |
echo "Provide env name; e.g. vencr <envname>" | |
else | |
rm -r $@ "$VENVROOT/$envname" && echo "Removed $VENVROOT/$envname" | |
fi | |
} | |
function venvl() { | |
# $1...: options to ls | |
ls $@ $VENVROOT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment