Preserve virtualenv prompt when duplicating panes #19158

Closed
opened 2026-01-31 06:35:25 +00:00 by claunia · 3 comments
Owner

Originally created by @brupelo on GitHub (Dec 31, 2022).

Consider this docs section https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory , I've already tried
to change the prompt env var to $e]9;9;$P$e\$P$G and works fairly ok. There is a catch though... let's say you've activated a python
virtualenv and you duplicate a pane... while the new environment (path + env.vars) will be inherited the prompt won't be the same than
before, is there any workaround for this one?

In conemu you'd have this nice behaviour out of the box.

Example when spawning this command

    {
        "command": 
        {
            "action": "splitPane",
            "split": "down",
            "splitMode": "duplicate"
        },
        "keys": "ctrl+shift+o"
    },

image

as you can see the duplicated bottom pane won't have the (venv) in the prompt

Originally created by @brupelo on GitHub (Dec 31, 2022). Consider this docs section https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory , I've already tried to change the prompt env var to `$e]9;9;$P$e\$P$G` and works fairly ok. There is a catch though... let's say you've activated a python virtualenv and you duplicate a pane... while the new environment (path + env.vars) will be inherited the prompt won't be the same than before, is there any workaround for this one? In conemu you'd have this nice behaviour out of the box. Example when spawning this command { "command": { "action": "splitPane", "split": "down", "splitMode": "duplicate" }, "keys": "ctrl+shift+o" }, ![image](https://user-images.githubusercontent.com/18058492/210119377-ea547c84-6b88-4848-9bc1-d172a32df74e.png) as you can see the duplicated bottom pane won't have the (venv) in the prompt
claunia added the Issue-QuestionNeeds-Tag-FixResolution-Answered labels 2026-01-31 06:35:26 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jan 3, 2023):

This is kinda a Hard problem. The Terminal can't really know about the env vars of the child subprocesses like that. (especially consider a scenario like ssh).

The closest we'll be able to do on that front is probably something like #2785, to have a set of environment variables in the settings for the profile manually.

Alternatively, you could just make a specific profile for that specific virtual environment, with the commandline something like cmd /k path/to/activate.bat.

In conemu you'd have this nice behaviour out of the box.

I'd be curious how they accomplish that without hooks of some sort - are they like, reporting every environment variable change up to the Terminal some how? That'd be... impractical, and impossible for CMD. Maybe that's a shell feature, of something like cmder? Maybe that's just a visual artifact, and not actually a full clone? Maybe they're just blindly copying the env vars from the first attached process to duplicated processes? That seems like a heuristic to me though

@zadjii-msft commented on GitHub (Jan 3, 2023): This is kinda a **H**ard problem. The Terminal can't really know about the env vars of the child subprocesses like that. (especially consider a scenario like `ssh`). The closest we'll be able to do on that front is probably something like #2785, to have a set of environment variables in the settings for the profile manually. Alternatively, you could just make a specific profile for that specific virtual environment, with the commandline something like `cmd /k path/to/activate.bat`. > In conemu you'd have this nice behaviour out of the box. I'd be curious how they accomplish that without hooks of some sort - are they like, reporting every environment variable change up to the Terminal some how? That'd be... impractical, and impossible for CMD. Maybe that's a shell feature, of something like cmder? Maybe that's just a visual artifact, and not actually a full clone? Maybe they're just blindly copying the env vars from the first attached process to duplicated processes? That seems like a heuristic to me though
Author
Owner

@brupelo commented on GitHub (Jan 4, 2023):

Mmm, I understand what you're saying there... In any case, I'd just like to know what's the best practice/feature to use here with wt.

Consider this scenario, having many dozens of python repos (if not hundreds) each one with their own virtualenv. Obviously it'd be nice having a plugin in your favourite text editor (vscode, sublime_text, atom, put_your_favourite_here) where you'd be able directly to spawn/activate your venv in wt, right? I mean, with conemu I had coded this sort of plugin in the past and it was pretty handy.

I'm thinking... is it possible to have "parametrized profiles"? Ie. can you inject external parameters to the profile? That way you'd be able to reuse the same profile amongst different venvs. Just thinking loud here.

Anyway, later on I'll play around with conemu and share my findings here... But what you're saying seems plausible and maybe conemu is using some sort of heuristic at the end of the day that won't work in the general case.

Here's a little example of creating/activating/splitting_horizontally/splitting_vertically in conemu though (vc=virtualenv creation, va=virtualenv activation)

image

@brupelo commented on GitHub (Jan 4, 2023): Mmm, I understand what you're saying there... In any case, I'd just like to know what's the best practice/feature to use here with wt. Consider this scenario, having many dozens of python repos (if not hundreds) each one with their own virtualenv. Obviously it'd be nice having a plugin in your favourite text editor (vscode, sublime_text, atom, put_your_favourite_here) where you'd be able directly to spawn/activate your venv in wt, right? I mean, with conemu I had coded this sort of plugin in the past and it was pretty handy. I'm thinking... is it possible to have "parametrized profiles"? Ie. can you inject external parameters to the profile? That way you'd be able to reuse the same profile amongst different venvs. Just thinking loud here. Anyway, later on I'll play around with conemu and share my findings here... But what you're saying seems plausible and maybe conemu is using some sort of heuristic at the end of the day that won't work in the general case. Here's a little example of creating/activating/splitting_horizontally/splitting_vertically in conemu though (vc=virtualenv creation, va=virtualenv activation) ![image](https://user-images.githubusercontent.com/18058492/210600936-291e81a8-97af-4284-9699-1171fa2a67c3.png)
Author
Owner

@carlos-zamora commented on GitHub (Jan 18, 2023):

We're keeping the discussion about parameterized profiles in #5571. We'd definitely like to make this easier, so feel free to chip in over there. We'd love to hear what you come up with 😊.

@carlos-zamora commented on GitHub (Jan 18, 2023): We're keeping the discussion about parameterized profiles in #5571. We'd definitely like to make this easier, so feel free to chip in over there. We'd love to hear what you come up with 😊.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19158