Skip to main content

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 activate and uv deactivate commands 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):

  1. <path>/.venv - Local .venv directory
  2. <path> itself (if it ends with .venv)
  3. ~/.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 ~/.bashrc or source ~/.zshrc).
  • Check that the uv-shell-hook command is available in your PATH.
  • 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.bat file is in a directory included in your system PATH.
  • Check the uv documentation 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

uv_shell_hook-0.1.6.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uv_shell_hook-0.1.6-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file uv_shell_hook-0.1.6.tar.gz.

File metadata

  • Download URL: uv_shell_hook-0.1.6.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uv_shell_hook-0.1.6.tar.gz
Algorithm Hash digest
SHA256 96bebd1b3a2a284fea4f7a59b378eef5ede17ebab8afdd4d57465be6d3184bce
MD5 d408fc706e802b4e74af624afe192193
BLAKE2b-256 3a57b42dc466a6ce40624205957032c9e260f2d33e62b00955f2b5117dca6af8

See more details on using hashes here.

Provenance

The following attestation bundles were made for uv_shell_hook-0.1.6.tar.gz:

Publisher: ci.yml on kdheepak/uv-shell-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file uv_shell_hook-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: uv_shell_hook-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uv_shell_hook-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 02cd93ed86caa3162cdd4efd73e74d57fe227c7dc528d1496ca16a484be8487b
MD5 7dd9b34108913e2592897c12a90a129b
BLAKE2b-256 915489aad751e89a5bece63c890102112b19bcd57a950d710c59e6b044e80e6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for uv_shell_hook-0.1.6-py3-none-any.whl:

Publisher: ci.yml on kdheepak/uv-shell-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page