How can I change my terminal color when activating a virtual environment?

0
1
Asked By TechieTurtle99 On

Hey everyone! I'm using a bash terminal and I've figured out how to change the terminal color when I open an SSH session by checking if the variable "$SSH_CONNECTION" is set. However, I want to achieve a similar effect when I activate a virtual environment. Unfortunately, when I check "$VIRTUAL_ENV", it comes out as null. Does anyone know how to change the terminal color based on virtual environment activation?

1 Answer

Answered By CuriousCoder47 On

It looks like you're using "$VIRTUAL_ENV" in your .bashrc, which only runs when the shell starts, so it doesn't trigger on virtual environment activation. Instead, you might want to add your color change logic directly in the activation script of your virtual environment. You can modify the "activate" script located in "venvname/bin/" to change your prompt color whenever you source it. Just a thought!

TechieTurtle99 -

That makes sense! I should have checked there. I'll try editing the "activate" script to see if that works. Thanks!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.