This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
venv-lite.zsh
74 lines (59 loc) · 1.69 KB
/
venv-lite.zsh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Andy's very mini virtualenvwrapper-ish zsh plugin
# This is a simple, lightweight zsh plugin providing these four
# commands, with this syntax and no other options:
#
# mkvirtualenv <venv-name>
# workon <venv-name>
# rmvirtualenv <venv-name>
# wipevenv
#
# mkvirtualenv creates venvs in ~/.virtualenv; when a venv is created,
# it is automatically activated too.
#
# workon and rmvirtualenv respectively activate and delete venvs in
# ~/.virtualenv; tab completion works for these commands, based on the
# directories in ~/.virtualenv
#
# mkvirtualenv uses whatever python is active, so use pyenv if you
# want to choose your python version.
#
# mkvirtualenv creates venvs using python's stdlib's venv module; as
# such, it only works for python versions >= 3.3.
#
# To create a venv for an earlier version of python (assuming pyenv
# and its virtualenv support are installed) just create the venv
# using, e.g.:
#
# $ virtualenv -ppython2.7 ~/.virtualenvs/<name of venv>
#
# after which you can use this plugin's workon and rmvirtualenv on
# that venv as usual.
#
# wipevenv wipes the currently active venv (if any - beware!), leaving
# only pip, setuptools, etc. in place.
#
# That's it!
_venvs_path() {
echo ~/.virtualenvs
}
_venv_path() {
echo "$(_venvs_path)/$1"
}
mkvirtualenv () {
python -m venv $(_venv_path $1)
workon $1
}
workon () {
source $(_venv_path $1)/bin/activate
}
rmvirtualenv () {
rm -rvf $(_venv_path $1) | wc -l
}
wipevenv() {
pip freeze --exclude-editable | xargs pip uninstall -y
pip list --editable --format freeze | xargs pip uninstall -y
}
_venv_completion () {
_path_files -/ -W "$(_venvs_path)"
}
compdef _venv_completion workon rmvirtualenv