Open BrightXiaoHan opened 9 months ago
useenv
useenv() {
local OLD_PATH=$PWD
local VENV_DIR=${1:-'.venv'} #default venv name
local FOUND
while [ -z "$FOUND" ] ; do
if ls ${VENV_DIR}/bin/activate 2>/dev/null >/dev/null ; then
source ${VENV_DIR}/bin/activate
FOUND='FOUND'
break
fi
if [ "/home/$USER" == "$PWD" ] || [ '/' == "$PWD" ] ; then
break
fi
cd ..
done
if [ -z "$FOUND" ] ;then
echo "venv not found"
else
VERSION=`python3 --version 2>&1`
printf 'Using %s\n' "$VERSION"
echo found on $PWD
fi
cd $OLD_PATH
}