mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-08-07 06:08:39 +02:00
Merge 79263e5833 into 0912e05c05
This commit is contained in:
commit
c46923f3a9
2 changed files with 36 additions and 0 deletions
10
plugins/uv-env/README.md
Normal file
10
plugins/uv-env/README.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# uv Environment Plugin
|
||||
|
||||
This plugin automatically activates the uv virtual environment when you cd into a project directory, and deactivates it when you cd out.
|
||||
Note: Script looks for pyproject.toml and uv.lock files to determine if it's a uv project
|
||||
|
||||
To use it, add `uv-env` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... uv-env)
|
||||
```
|
||||
26
plugins/uv-env/uv-env.plugin.zsh
Normal file
26
plugins/uv-env/uv-env.plugin.zsh
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
_toggleUvShell() {
|
||||
local in_uv_dir=0
|
||||
if [[ -f "$PWD/pyproject.toml" && -f "$PWD/uv.lock" ]]; then
|
||||
in_uv_dir=1
|
||||
fi
|
||||
|
||||
if [[ $uv_active -eq 1 ]] && { [[ $in_uv_dir -eq 0 ]] || [[ "$PWD" != "$uv_dir" && "$PWD" != "$uv_dir"/* ]]; }; then
|
||||
export uv_active=0
|
||||
unset uv_dir
|
||||
(( $+functions[deactivate] )) && deactivate
|
||||
fi
|
||||
|
||||
if [[ $in_uv_dir -eq 1 ]] && [[ $uv_active -ne 1 ]]; then
|
||||
venv_dir="${UV_PROJECT_ENVIRONMENT:-$PWD/.venv}"
|
||||
[[ "$venv_dir" != /* ]] && venv_dir="$PWD/$venv_dir"
|
||||
|
||||
if [[ -f "${venv_dir}/bin/activate" ]]; then
|
||||
export uv_active=1
|
||||
export uv_dir="$PWD"
|
||||
source "${venv_dir}/bin/activate"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook chpwd _toggleUvShell
|
||||
_toggleUvShell
|
||||
Loading…
Reference in a new issue