https://github.com/skylor-tang/auto-venv
A Zsh plugin that automatically activates the Python virtual environment in the current directory or its parent directories.
https://github.com/skylor-tang/auto-venv
zplug zsh-plugin zshrc
Last synced: 8 months ago
JSON representation
A Zsh plugin that automatically activates the Python virtual environment in the current directory or its parent directories.
- Host: GitHub
- URL: https://github.com/skylor-tang/auto-venv
- Owner: Skylor-Tang
- License: mit
- Created: 2024-04-27T06:55:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-05T12:47:00.000Z (over 1 year ago)
- Last Synced: 2024-12-23T14:32:50.167Z (10 months ago)
- Topics: zplug, zsh-plugin, zshrc
- Language: Shell
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# auto-venv
`auto-venv` is a Zsh plugin that automatically activates the Python virtual environment in the current directory or its parent directories.
## Installation
Use [zplug](https://github.com/zplug/zplug) to install the plugin:
```bash
zplug "Skylor-Tang/auto-venv", use:auto-venv.zsh, from:github, at:main
```## Usage
The plugin automatically detects if there is a `venv` or `.venv` directory in the current directory or its parent directories, and activates the corresponding Python virtual environment.
When you change directories, the plugin will automatically detect and activate the virtual environment. If the current directory does not have a virtual environment, but you are currently in an active virtual environment, the plugin will automatically deactivate the current virtual environment.
## How it Works
The plugin uses the Zsh `chpwd` hook function to automatically call the `auto_venv` function when you change directories. This function recursively searches the parent directories until it finds a virtual environment directory or reaches the root directory or the user's home directory.
## Considerations
- This plugin assumes that your Python virtual environments are located in the `venv` or `.venv` subdirectories of your project directories.
- If you use other virtual environment management tools, such as `pipenv` or `poetry`, this plugin may not work as expected. In such cases, you may need to write custom activation logic.## License
This plugin is released under the MIT license.