Last active
March 20, 2019 14:28
-
-
Save antoinebou12/a2975cc53f52da16265df21559b90a74 to your computer and use it in GitHub Desktop.
Select virtualenv for python virtualenv in a directory
This file contains hidden or 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
#!/bin/bash | |
# Exemple | |
# Choose your virtualenv for crispml: | |
# 1 reader | |
# 2 curses | |
# 3 twisted | |
function select_virtenv() { | |
echo "$1" | |
if [ -z "$1" ]; then | |
DIR="$(pwd)" | |
else | |
DIR="$1" | |
fi | |
# User input | |
echo -e "\e[33mChoose your virtualenv for crispml: " | |
# associative file to a number | |
NFILE=1 | |
declare -A FLIST | |
for f in "$DIR/*"; do | |
FLIST[$NFILE]=$(basename $f) | |
echo -e "\e[96m $NFILE " ${FLIST[$NFILE]} | |
let "NFILE=NFILE+1" | |
done | |
# User input | |
read -p $'\e[39mEnter the number(q to quit): \e[0m' NUM | |
#check for number | |
while ! [[ "$NUM" =~ ^[0-9]+$ ]]; do | |
if [ "$NUM" = 'q' ] ; then | |
return | |
else | |
read -p $'\e[39mEnter the number(q to quit): \e[0m' NUM | |
fi | |
done | |
# activate | |
VEDIR=$DIR/${FLIST[$NUM]} | |
if [ -d "$VEDIR" ]; then | |
cd "$VEDIR" | |
source bin/activate | |
fi | |
} | |
#select_virtenv | |
#select_virtenv ~/path/to/dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment