-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpyenv.zsh
More file actions
42 lines (38 loc) · 1.43 KB
/
Copy pathpyenv.zsh
File metadata and controls
42 lines (38 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
if (( $+commands[pyenv] ))
then
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export PYENV_ROOT="$HOME/.pyenv"
echo "Loading pyenv.."
eval "$(pyenv init - zsh)"
eval "$(pyenv virtualenv-init - zsh)"
# Make sure we don't accidentally forgot to use pyenv-virtualenv instead of plain python -m venv
python_venv_warning() {
local cmd=$1
shift
if [[ $1 == "-m" && $2 == "venv" && $3 ]]; then
echo "Warning: You are about to create a virtual environment without pyenv-virtualenv."
echo
read "reply?Are you sure you want to continue? (y/N) "
if [[ ! $reply =~ ^[Yy]$ ]]; then
echo
echo "Syntax for creating a virtual environment with pyenv-virtualenv:"
echo " pyenv virtualenv <python_version> <env_name>"
echo
read "use_pyenv?Would you like to create a pyenv-virtualenv now? (Y/n) "
if [[ ! $use_pyenv =~ ^[Nn]$ ]]; then
local project_name=$(basename "$PWD")
read "env_name?Enter a name for the virtual environment (default: $project_name): "
env_name=${env_name:-$project_name}
echo "Creating a pyenv-virtualenv named '$env_name'..."
pyenv virtualenv $(pyenv version-name) $env_name
pyenv local $env_name
fi
return 1
fi
fi
command $cmd "$@"
}
alias python='python_venv_warning python'
alias python2='python_venv_warning python2'
alias python3='python_venv_warning python3'
fi