Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

zsh-venv-auto

  • oh-my-zsh plugin
  • Automaticall activate and deactivate Python Virtual Environment when you change directory
  • Installed Virtual Environment directory name must be one of venv, env, .venv, .env

Installation

git clone https://github.com/peppy0510/zsh-venv-auto.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-venv-auto
  • Add zsh-venv-auto to ~/.zshrc plugins section.
vim ~/.zshrc
zsh-venv-auto
  • Add the initial activation to the end of ~/.zshrc, below every PATH export.
(( $+functions[auto_activate_venv] )) && auto_activate_venv

Why the activation call is separate

The plugin deliberately does not activate on load. A venv's activate snapshots PATH into _OLD_VIRTUAL_PATH, and deactivate restores that snapshot verbatim. oh-my-zsh sources plugins near the top of ~/.zshrc, so activating at load time snapshots a PATH that is missing everything set further down — nvm's node, JAVA_HOME, CUDA. The first cd out of that venv then restores the half-built snapshot and those tools silently vanish from PATH. Calling auto_activate_venv at the very end instead makes the snapshot complete.

About

zsh-venv-auto

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages