]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / autoenv / autoenv.plugin.zsh
1 # Initialization: activate autoenv or report its absence
2 () {
3 local d autoenv_dir install_locations
4 if ! type autoenv_init >/dev/null; then
5   # Check if activate.sh is in $PATH
6   if (( $+commands[activate.sh] )); then
7     autoenv_dir="${commands[activate.sh]:h}"
8   fi
9
10   # Locate autoenv installation
11   if [[ -z $autoenv_dir ]]; then
12     install_locations=(
13       ~/.autoenv
14       ~/.local/bin
15       /usr/local/opt/autoenv
16       /opt/homebrew/opt/autoenv
17       /usr/local/bin
18       /usr/share/autoenv-git
19       ~/Library/Python/bin
20     )
21     for d ( $install_locations ); do
22       if [[ -e $d/activate.sh ]]; then
23         autoenv_dir=$d
24         break
25       fi
26     done
27   fi
28
29   # Look for Homebrew path as a last resort
30   if [[ -z "$autoenv_dir" ]] && (( $+commands[brew] )); then
31     d=$(brew --prefix)/opt/autoenv
32     if [[ -e $d/activate.sh ]]; then
33       autoenv_dir=$d
34     fi
35   fi
36
37   # Complain if autoenv is not installed
38   if [[ -z $autoenv_dir ]]; then 
39     cat <<END >&2
40 -------- AUTOENV ---------
41 Could not locate autoenv installation.
42 Please check if autoenv is correctly installed.
43 In the meantime the autoenv plugin is DISABLED.
44 --------------------------
45 END
46     return 1
47   fi
48   # Load autoenv
49   source $autoenv_dir/activate.sh
50 fi
51 }
52 [[ $? != 0 ]] && return $?
53
54 # The use_env call below is a reusable command to activate/create a new Python
55 # virtualenv, requiring only a single declarative line of code in your .env files.
56 # It only performs an action if the requested virtualenv is not the current one.
57
58 use_env() {
59   local venv
60   venv="$1"
61   if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
62     if workon | grep -q "$venv"; then
63       workon "$venv"
64     else
65       echo -n "Create virtualenv $venv now? (Yn) "
66       read answer
67       if [[ "$answer" == "Y" ]]; then
68         mkvirtualenv "$venv"
69       fi
70     fi
71   fi
72 }