I use gnome-terminal with zsh. I recently had an issue with keeping the current working directory when opening a new tab (CTRL+SHIFT+T) since it used to reset itself to $HOME
everytime. I solved it by adding:
. /etc/profile.d/vte.sh
to the .zshrc
file.
Now, since I use virtualenv (and virtualenvwrapper) I would like to avoid having to do workon virtualenv_name
each time I open a new tab.
The obvious solution is to put that command in the .zshrc
, however I don't want to always enter the virtualenv. I want to do it only when I open a new tab and I am already inside a virtualenv.
Now, since a virtualenv is just a modification to PATH
, PS1
, and stuff like that, I guess I can do this in some way. Any ideas?
You don't specifically need to activate an environment; activation just prepends the virtual environment's binary directory to your path, so that “python” invokes the virtual environment's Python interpreter and you can run installed scripts without having to use their full path.
Simply cd into a project directory with a python virtual environment setup (with any of these names: venv/ , . venv/ , env or . env ), and the script will activate it automatically for you (just as you would do with source ./venv/bin/activate ).
These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.
Use one of the auto export solutions, e.g. https://direnv.net or https://github.com/kennethreitz/autoenv. These solutions can be used to turn on a virtual env when cding into its directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With