Last active
February 16, 2024 07:59
-
-
Save xurble/01092ad42edbbc2b8f611c9801f36c65 to your computer and use it in GitHub Desktop.
Python venv selection function for .zshrc
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
function ve() { | |
printf "Select a venv:\n" | |
# Populate venv_list array with folder names | |
venv_list=() | |
i=1 | |
for d in ~/venvs/*/; do | |
folder_name=$(basename "$d") | |
venv_list+=("$folder_name") | |
printf "%d) %s\n" "$i" "$folder_name" | |
((i++)) | |
done | |
# Prompt user for selection | |
read "selection?Enter number: " | |
# Validate selection | |
if ((selection >= 1 && selection < i)); then | |
selected_folder="${venv_list[selection]}" | |
source ~/venvs/"$selected_folder"/bin/activate | |
echo "Activated virtual environment: $selected_folder" | |
# Switch BBEdit language server to the new venv | |
rm ~"/Library/Application Support/BBEdit/Language Servers/pylsp" | |
ln -s ~/venvs/"$selected_folder"/bin/pylsp ~"/Library/Application Support/BBEdit/Language Servers/pylsp" | |
else | |
echo "Invalid selection" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment