-
Notifications
You must be signed in to change notification settings - Fork 2
/
pyautoenv.bash
46 lines (42 loc) · 1.55 KB
/
pyautoenv.bash
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
# pyautoenv Automatically activate and deactivate Python environments.
# Copyright (C) 2023 Harry Saunders.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
if ! [[ $- == *i* ]]; then
# do not activate if the shell is not interactive
return
fi
if ! [ "$(type cd)" == "cd is a shell builtin" ]; then
>&2 echo "pyautoenv: cd is non-default, aborting activation so things don't break!"
return
fi
_bash_pyautoenv_path="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
function _bash_pyautoenv_activate() {
if [ "${PYAUTOENV_DISABLE-0}" -ne 0 ]; then
return
fi
if [ -z "$(command -v python3)" ]; then
return
fi
local pyautoenv_py="${_bash_pyautoenv_path}/pyautoenv.py"
if [ -f "${pyautoenv_py}" ]; then
eval "$(python3 "${pyautoenv_py}")"
fi
}
function _bash_pyautoenv_version() {
python3 "${_bash_pyautoenv_path}/pyautoenv.py" --version
}
function cd() {
builtin cd "$@" && _bash_pyautoenv_activate
}