Team,
As I'm using a lot of virtual environments with PIPENV, it became harder to keep track of the environments that I have setup. And that was the reason to create this script which:
- List all of your (pipenv) virtual environments
- Select one
- Change to the actual folder
Requirements
- MacOS
- use of Pipenv (instead of the default virtualenv)
Script:
#!/bin/zsh
my_env_folder="$HOME/.local/share/virtualenvs"
#__Steps are documented in the 'echo' commands below
clear
echo "__1__LIST env folders with a number, user enters env number"
ls $my_env_folder | cat -n
read a
clear
echo "\n__2__SET the selected FOLDER name"
my_env_selected=`ls $my_env_folder | head -n $a | tail -n 1`
my_env_selected=$my_env_folder/$my_env_selected
echo " $my_env_selected\n"
echo "__3__CHANGE to the ACTUAL env folder name found in the envs '.project' file\n"
real_folder=`cat $my_env_selected/.project`
DIR=$( cd "${real_folder}" && pwd )
cd "${DIR}"
echo "__4__DONE!\n CURRENT FOLDER: $PWD\n NEXT: activate your virtual environment\n\n"
# IF all fails, the following line copies "cd folder_name"
# Next, press CMD-V and then ENTER.
echo "cd $real_folder" | pbcopy
When you run the script it will list your virtual environments and ask you to enter the number of the virtual environment you want to use. Then it will read the actual folder name of that environment in the .storage file and change to that folder.
Enjoy!
More Webex Development related resources? https://cs.co/webexdevinfo
Does the code not change to the right folder?
You could add the following lines to copy the destination foldername. So you only have to paste + press enter.
# IF all fails, the following line copies "cd folder_name"
# Next, press CMD-V and then ENTER.
echo "cd $real_folder" | pbcopy