mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-06 02:51:32 +01:00
feat(python): don't auto-deactivate in a subdir
This commit is contained in:
parent
26b3467806
commit
1965d1b3fc
2 changed files with 15 additions and 8 deletions
|
|
@ -32,8 +32,8 @@ virtual environments:
|
||||||
`venv`) in the current directory.
|
`venv`) in the current directory.
|
||||||
|
|
||||||
- `auto_vrun`: Automatically activate the venv virtual environment when entering a directory containing
|
- `auto_vrun`: Automatically activate the venv virtual environment when entering a directory containing
|
||||||
`<venv-name>/bin/activate`, and automatically deactivate it when navigating out of it (including
|
`<venv-name>/bin/activate`, and automatically deactivate it when navigating out of it (keeps venv activated
|
||||||
subdirectories!).
|
in subdirectories).
|
||||||
- To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh.
|
- To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh.
|
||||||
- Plugin activates first virtual environment in lexicographic order whose name begins with `<venv-name>`.
|
- Plugin activates first virtual environment in lexicographic order whose name begins with `<venv-name>`.
|
||||||
The default virtual environment name is `venv`. To use a different name, set
|
The default virtual environment name is `venv`. To use a different name, set
|
||||||
|
|
|
||||||
|
|
@ -86,12 +86,19 @@ function mkv() {
|
||||||
|
|
||||||
if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
|
if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
|
||||||
# Automatically activate venv when changing dir
|
# Automatically activate venv when changing dir
|
||||||
auto_vrun() {
|
function auto_vrun() {
|
||||||
for activator in "${PYTHON_VENV_NAME}"*/bin/activate(N); do
|
local dirname="$PWD"
|
||||||
if [[ -f "${activator}" ]]; then
|
|
||||||
source "${activator}" > /dev/null 2>&1
|
while
|
||||||
return
|
for activator in "${dirname}/${PYTHON_VENV_NAME}"*/bin/activate(N); do
|
||||||
fi
|
if [[ -f "${activator}" ]]; then
|
||||||
|
source "${activator}" > /dev/null 2>&1
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[[ -n "$dirname" ]]
|
||||||
|
do
|
||||||
|
dirname=${dirname%/*}
|
||||||
done
|
done
|
||||||
|
|
||||||
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
|
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue