terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Preserve virtualenv prompt when duplicating panes

Open brupelo opened this issue 2 years ago • 2 comments

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

brupelo avatar Dec 31 '22 00:12 brupelo

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 avatar Jan 03 '23 21:01 zadjii-msft

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 avatar Jan 04 '23 16:01 brupelo

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 avatar Jan 18 '23 22:01 carlos-zamora