Skip to content

Instantly share code, notes, and snippets.

@jmbwell
Created December 2, 2021 20:24
Show Gist options
  • Save jmbwell/c1e0f008a3abed7e182e40bc8308f380 to your computer and use it in GitHub Desktop.
Save jmbwell/c1e0f008a3abed7e182e40bc8308f380 to your computer and use it in GitHub Desktop.
zsh autocompletion for activating python virtualenvs
# zsh example for python virtualenv activation shortcuts with autocomplete
#
# - Assumes your virtualenvs are stored in the directory ~/virtualenvs
#
# To use, type activate, then press tab to get a list of available virtualenvs
# Example: act<tab> ans<tab> to do "activate ~/virtualenvs/ansible"
# 1. Activate enhanced completion in zsh
autoload -Uz compinit && compinit
# 2. Create alias shortcut to activate a python virtualenv
activate() { source ~/virtualenvs/$1/bin/activate }
# 3. Define autocomplete for available virtualenvs
compdef '_files -W $HOME/virtualenvs -/ -S "" -F "*/*"' activate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment