Search code examples
terminalzshpython-venvoh-my-zsh

How to change design of activated venv info for a zsh theme?


I've written up a custom zsh theme but can't get the color of the background for the activated venv information to match the arrow design (see picture below). I tried fiddling with $VIRTUAL_ENV and can color the area around the venv information, but I can't seem to edit the actual venv information itself.

In this example, I'd like to color the background of the activated venv "midas" (loaded on the first line via an alias) white to match the text ($(username))to the right of it. Here is a screenshot of my terminal and design. If helpful, the code can be found here in my GitHub repo.

Any thoughts or help appreciated. Thank you!


Solution

  • First, you'll need to tell virtualenv not to add anything to your prompt. To do so, add this:

    export VIRTUAL_ENV_DISABLE_PROMPT=1
    

    Then, you'll need to add a new section to your prompt, where you detect whether a virtual environment is active:

    if [[ -v VIRTUAL_ENV ]]; then
      # Insert code that adds stuff to your prompt.
    fi
    

    In there, you can use $VIRTUAL_ENV to get the name of the currently active virtual environment.