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
  • Smart virtual environment discovery: Automatically finds virtual environments in multiple locations
  • Consistent interface: Same uv activate and uv deactivate commands across all shells
  • Colorized output: Clear visual feedback with colored status messages

Installation

pip install uv-shell-hook

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>/.venv - Named environment in virtualenvs directory
  4. ~/.virtualenvs/<name> - Named environment directory (uses $WORKON_HOME if set)
# 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/
uv activate myproject

# 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

Examples

Example 1: Project-local Virtual Environment

cd my-python-project
uv venv                    # Create .venv in current directory
uv activate                # Activate the .venv
# (my-python-project) $
uv add requests           # Install packages
uv deactivate             # Deactivate when done

Example 2: Named Virtual Environment

# Create a named environment
uv venv ~/.virtualenvs/data-analysis

# Activate from anywhere
cd /some/other/directory
uv activate data-analysis  # Activates ~/.virtualenvs/data-analysis/.venv

Example 3: Multiple Virtual Environments

# Work with different projects
uv activate web-app        # Activate ~/.virtualenvs/web-app/.venv
uv deactivate

uv activate data-science   # Activate ~/.virtualenvs/data-science/.venv
uv deactivate

uv activate ./local-project  # Activate ./local-project/.venv

Troubleshooting

Virtual Environment Not Found

If you get "Virtual environment directory not found", check:

  1. The virtual environment exists in one of the search locations
  2. You have the correct permissions to access the directory
  3. The activation script exists in the Scripts/ (Windows) or bin/ (Unix) subdirectory

Function Not Available

Make sure you've properly added the shell function to your profile and restarted your shell or sourced the profile file.

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.1.tar.gz (11.7 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.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: uv_shell_hook-0.1.1.tar.gz
  • Upload date:
  • Size: 11.7 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.1.tar.gz
Algorithm Hash digest
SHA256 ae6454b3354020948eb0f335613ed3b170626adfb1ebb29f26e2a62424a5f3c6
MD5 d2c76ffa3d68ef2fb9f52bae6e262836
BLAKE2b-256 e4d8d962b8af91cc957ee302af884653e915e8fe8da054067b710f3ab12c76ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for uv_shell_hook-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: uv_shell_hook-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7d01fe06996ec945a4309fa506dbe578afe0cfec1a4c6067bbaab1bab487a15
MD5 6b3a8d203d31d7c85381cdbd829cc69a
BLAKE2b-256 bac808233d9da299be4947790bf3453d6e4f50ed1344cbd4c2de43f61adb6486

See more details on using hashes here.

Provenance

The following attestation bundles were made for uv_shell_hook-0.1.1-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