This package provides a shell hook for uv allowing activating and deactivating virtual environments.
Project description
uv-shell-hook
A cross-platform shell integration for uv that adds convenient
uv activate and uv deactivate commands to manage Python virtual environments across different
shells and operating systems.
Features
- Cross-platform support: Works on Linux, macOS, and Windows
- Multi-shell support: bash, zsh, Fish, PowerShell, and Windows CMD
- Consistent interface: Same
uv activateanduv deactivatecommands across all shells - Virtual environment discovery: Automatically finds virtual environments in multiple locations
Installation
$ uv tool install uv-shell-hook
$ uv-shell-hook --help
# or use it with uvx directly
$ uvx uv-shell-hook --help
Quick Start
Choose your shell and follow the setup instructions below:
Bash
Add the uv function to your shell:
# Add to ~/.bashrc or ~/.bash_profile
eval "$(uv-shell-hook bash)"
Or manually add the function:
uv-shell-hook bash >> ~/.bashrc
source ~/.bashrc
Zsh
Add the uv function to your shell:
# Add to ~/.zshrc
eval "$(uv-shell-hook zsh)"
Or manually add the function:
uv-shell-hook zsh >> ~/.zshrc
source ~/.zshrc
Fish
Add the uv function to your shell:
# Add to ~/.config/fish/config.fish
uv-shell-hook fish | source
Or manually add the function:
uv-shell-hook fish >> ~/.config/fish/config.fish
PowerShell
Add the uv function to your PowerShell profile:
# Add to your PowerShell profile (run $PROFILE to see location)
uv-shell-hook powershell | Out-String | Invoke-Expression
Or save it permanently:
uv-shell-hook powershell | Add-Content $PROFILE
Windows CMD
Save the batch script and add it to your PATH:
# Save the batch script
uv-shell-hook cmd > uv.bat
# Move to a directory in your `PATH` (e.g., C:\Windows\System32 or create a local bin directory)
move uv.bat C:\Users\%USERNAME%\bin\
Make sure the directory containing uv.bat is in your system PATH.
Usage
Once installed, you can use the enhanced uv commands in any supported shell:
Activate a Virtual Environment
The uv activate command will search for virtual environments in the following locations (in
order):
<path>/.venv- Local .venv directory<path>itself (if it ends with.venv)~/.virtualenvs/<name>- Named environment directory
# Activate virtual environment in current directory
uv activate
# Activate virtual environment in specific path
uv activate ./my-project
# Activate virtual environment by name from ~/.virtualenvs/my-project
# i.e. mimic `workon myproject` from virtualenvwrapper or `conda activate myproject` from conda
uv activate my-project
# Activate specific .venv path
uv activate /path/to/project/.venv
Deactivate Virtual Environment
# Deactivate currently active virtual environment
uv deactivate
Other uv Commands
All other uv commands work exactly as before:
uv init
uv add requests
uv run python script.py
uv sync
# ... any other `uv` command
Troubleshooting
If you encounter issues, try the following:
- Ensure the shell configuration file is sourced correctly (e.g.,
source ~/.bashrcorsource ~/.zshrc). - Check that the
uv-shell-hookcommand is available in yourPATH. - Verify that the virtual environment exists in the expected location.
- If using Fish, ensure you have the latest version of Fish shell that supports the syntax used.
- For PowerShell, ensure your execution policy allows running scripts
(
Set-ExecutionPolicy RemoteSigned). - If you have issues with CMD, ensure the
uv.batfile is in a directory included in your systemPATH. - Check the
uvdocumentation for any updates or changes to command usage. - If you have custom virtual environment locations, ensure they are correctly set in your shell configuration.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uv_shell_hook-0.1.7.tar.gz.
File metadata
- Download URL: uv_shell_hook-0.1.7.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
452c57329da781167ac69aeb135b0e2fd9ff5f2f6d17df2f1ac017a64a365b78
|
|
| MD5 |
bac036e7a5672eff63dd5f0938216a7e
|
|
| BLAKE2b-256 |
57c57be24b1f063342520952f0c094c772eb1826244b7c4bfe0dda79afa8d18d
|
Provenance
The following attestation bundles were made for uv_shell_hook-0.1.7.tar.gz:
Publisher:
ci.yml on kdheepak/uv-shell-hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uv_shell_hook-0.1.7.tar.gz -
Subject digest:
452c57329da781167ac69aeb135b0e2fd9ff5f2f6d17df2f1ac017a64a365b78 - Sigstore transparency entry: 330714832
- Sigstore integration time:
-
Permalink:
kdheepak/uv-shell-hook@9501998e2907c11709ecde7aa87c5c51e8f664ee -
Branch / Tag:
refs/tags/v0.1.7 - Owner: https://github.com/kdheepak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@9501998e2907c11709ecde7aa87c5c51e8f664ee -
Trigger Event:
release
-
Statement type:
File details
Details for the file uv_shell_hook-0.1.7-py3-none-any.whl.
File metadata
- Download URL: uv_shell_hook-0.1.7-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01ad10dee69931e6f94e61a916921c2b7abfa9f06982cef733660c37df410629
|
|
| MD5 |
2f69c38f69b889f02af7987be5cc603a
|
|
| BLAKE2b-256 |
bad24617793bd864560ce1c31e1644da739d0224be3b03c5784e19d6536f6473
|
Provenance
The following attestation bundles were made for uv_shell_hook-0.1.7-py3-none-any.whl:
Publisher:
ci.yml on kdheepak/uv-shell-hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uv_shell_hook-0.1.7-py3-none-any.whl -
Subject digest:
01ad10dee69931e6f94e61a916921c2b7abfa9f06982cef733660c37df410629 - Sigstore transparency entry: 330714880
- Sigstore integration time:
-
Permalink:
kdheepak/uv-shell-hook@9501998e2907c11709ecde7aa87c5c51e8f664ee -
Branch / Tag:
refs/tags/v0.1.7 - Owner: https://github.com/kdheepak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@9501998e2907c11709ecde7aa87c5c51e8f664ee -
Trigger Event:
release
-
Statement type: