2

I'm on Windows 10 and have WSL1 Ubuntu. On Windows Terminal, I have a profile for it called "Ubuntu". (For this question, assume I cannot change those tools - for instance, I can't upgrade to WSL2, I can't install a different terminal emulator.)

On WSL1 Ubuntu, I wrote a command in the .bashrc so that, whenever I start this profile, it will automatically run that command in Ubuntu.

I would like to create a separate profile that goes to the SAME Ubuntu installation, but runs a DIFFERENT command on startup.

My first thought was to create a new profile (by duplicating the Ubuntu profile) and, somehow, get it to source a different .bashrc file with the other command.

I thought I can edit the settings.json file to modify the wsl.exe command that starts Ubuntu - but I have not found a way to pass a command for it to run in Ubuntu once it's been started up.

Is there any way to create separate Windows Terminal profiles for the same WSL1 Ubuntu installation that just run different commands at start-up, or source different bashrc files on startup?

3
  • What version of Windows Terminal are you running? What is and isn't possible will heavily been reliant on that information.
    – Ramhound
    Aug 31, 2021 at 21:50
  • @Ramhound Thanks, sorry - how can I find out what version I am running?
    – cheryllium
    Sep 2, 2021 at 19:15
  • There is a button/menu item that will display the version information. If the system is updated, then it's likely 1.10 but, whoever installed Windows Terminal would know the answer to my question.
    – Ramhound
    Sep 2, 2021 at 19:35

1 Answer 1

2

There are several types of Windows Terminal profiles:

  • Dynamically generated profiles: This is what you are likely seeing by default with the Ubuntu profile. When starting up, Windows Terminal queries several "sources" for the shells that are installed, one of these being "Windows.Terminal.Wsl". You should see this if looking at your settings.json as the "source": "Windows.Terminal.Wsl" property on the profile.

  • There's a fairly recent "JSON fragment extension", which lets third-party installers insert their own profile fragment by storing it in a well-known directory.

  • And then there's the "basic" user-managed profile, which is what you are looking for in this case. Assuming you are using a fairly recent Windows Terminal release, it's easiest just to use the Settings GUI to create a new profile and set the Command Line there. But if you want to use settings.json, you'll typically want to substitute a "commandline" property instead of "source". For example:

    {
        "commandline": "wsl.exe ~ -e tmux", 
        "name": "Ubuntu w/Tmux"
    },
    {
        "commandline": "wsl.exe ~ -e python3", 
        "name": "Python REPL in Ubuntu"
    },
    ...
    
    

    The ~ option starts WSL in the user's Linux $HOME directory. It must be the first option after the wsl command. -e command, as you probably expect, executes an alternative command on startup.

It would be best to remove the command that you've added to ~/.bashrc and simply create two profiles -- One for each command you want to start.

But if you really did want two separate ~/.bashrc files, then the "commandline" would look something like (untested):

wsl.exe ~ -e bash --rcfile ~/.other_bashrc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .