]> arthur.barton.de Git - ax-zsh.git/blob - plugins/virtualenv/virtualenv.zshrc
virtualenv: Add support for "pipenv"
[ax-zsh.git] / plugins / virtualenv / virtualenv.zshrc
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # virtualenv: Activate an "virtual environment"
3
4 # This plugin is optional.
5 [[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
6
7 function activate() {
8         local d r
9
10         # Make sure no "virtual environment" is already active!
11         if [[ -n "$VIRTUAL_ENV" ]]; then
12                 echo "Oops, looks like a virtual environment is already active!" >&2
13                 return 1
14         fi
15
16         if [[ -r Pipfile ]]; then
17                 pipenv run "$SHELL"; r=$?
18                 return $r
19         fi
20         for d (
21                 ./bin
22                 ./env/bin
23                 ./venv/bin
24                 ./.venv/bin
25         ); do
26                 script="$d/activate"
27                 test -r "$script" || continue
28
29                 # Read in activation script fragment ...
30                 source "$script" && return 0
31
32                 echo "Failed to read script \"$script\"!" >&2
33                 return 1
34         done
35
36         echo "No virtual environment found!" >&2
37         return 1
38 }
39
40 if [[ -n "$PIPENV_ACTIVE" ]]; then
41         alias deactivate=exit
42 fi