Skip to content

Instantly share code, notes, and snippets.

@xurble
Last active February 16, 2024 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xurble/01092ad42edbbc2b8f611c9801f36c65 to your computer and use it in GitHub Desktop.
Save xurble/01092ad42edbbc2b8f611c9801f36c65 to your computer and use it in GitHub Desktop.
Python venv selection function for .zshrc
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