Search code examples
virtualenvfishvirtualfish

Set virtualenv name in Fish shell, directly in config.fish


The documentation of virtualfish specifices that in order to get the fish prompt to show the current virtualenv you should update the global fish_prompt function and save it (funced fish_prompt and funcsave fish_prompt). I don't find that approach particular elegant, as I would like to have all my customizations in config.fish. My question is therefore, what is the simplest approach to show the current virtualenv name in the fish prompt by only making changes in config.fish?

So if foobar is the name of the current environment, how to show it like:

(foobar) gedefar@Jakobs-MacBook-Pro ~/w/pyprototypes`

Solution

  • The simplest approach I found was by overriding the fish_prompt function in config.fish

    functions -c fish_prompt _old_fish_prompt
    function fish_prompt
      if set -q VIRTUAL_ENV
        echo -n -s (set_color -b blue white) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal) " "
      end
      _old_fish_prompt
    end