0

I just installed Windows terminal and automatically got it working with my Ubuntu 18.04 WSL, appearing in the right-click menu as well, and was able to easily set it to the default shell upon launch of Windows Terminal.

However, in my usual workflow, I also directly use the ubuntu1804.exe that I have in my WSL installation directory in an external drive (in the directory that also contains the rootfs directory of the WSL installation).

This is handy to me because it opens in the /home/$USER directory and can be added as a separate icon in the taskbar, whereas Windows terminal from the taskbar opens in /mnt/c/Users/$USER.

This ubuntu1804.exe seems to open in a different console, and can't get it to open in Windows Terminal.

Is there any wsl command line setting to choose the Windows Terminal as the default environment, or any other way to get this.

2
  • Have you looked at WSL profiles? You should be able to setup a profile to point to the exe that you want and even specify the starting directory.
    – heavyd
    Commented Mar 4, 2021 at 16:04
  • Thank you for your comment! I saw this at the same time as an answer was submitted, I think WSL profiles are covered there! Commented Mar 5, 2021 at 8:37

1 Answer 1

0

As some background, ubuntu1804.exe is simply a Windows "App execution alias" (just type that at the Start menu to see the corresponding Windows settings screen). It basically runs the Microsoft Store (formerly known as UWP) app. That app, as you've found, launches its own terminal, known by the (horrible) name "Ubuntu Terminal". I'm sure there's some underlying terminal version that they used, but I'm not exactly sure what it is.

As you've already discovered, Windows Terminal is a much nicer option.

As it has done for you, Windows Terminal will auto-detect WSL instances installed from the Store and dynamically create a profile for it. But it may not launch exactly the way you want (e.g. starting directory).

The other thing you need to know is that the wsl.exe command is a better way to launch instances rather than ubuntu1804.exe.

I think I hear two related questions:

  • First, how to have Windows Terminal launch Ubuntu to the home directory instead of %userprofile
  • Second, how to launch that from the commandline (so that you can create a shortcut to pin on the taskbar, for instance).

You could fix your issue (at least) two ways. The first would be to modify your startup script. I personally don't recommend this -- The second option is better, IMHO. But if you want to, I'd modify .profile (since you probably only want this to happen in a login shell). And just add your cd ~ at the bottom. I haven't tested this, but it should work assuming that ubuntu1804.exe launches the default shell as a login shell. There's a chance that it doesn't.

The better option, though, is to modify the Windows Terminal profile for your Ubuntu 18.04 instance. I'm going to give some "extra" instructions here in case you (or someone who finds this answer in the future) has more than one WSL instance/distribution installed:

  • First, run wsl.exe -l -v (in PowerShell, Ubuntu WSL, or CMD). Take note of the name of your instance. I'm going to assume this is Ubuntu18.04 for the commands below.

  • Then, in Windows Terminal, open Settings (Ctrl+, by default, or use the menu).

  • Look for your Ubuntu 18.04 profile. It should be something like this:

    {
        "guid": "{unique-to-you}",
        "hidden": false,
        "name": "Ubuntu 18.04",
        "source": "Windows.Terminal.Wsl",
    },
    

    The source is for the Dynamic Profile.

  • Since you're going to give it your own profile settings, comment that out. And add a commandline option like so:

    {
        "guid": "{unique-to-you}",
        "hidden": false,
        "name": "Ubuntu18.04",
        //"source": "Windows.Terminal.Wsl",
        "commandline": "wsl.exe ~ -d Ubuntu18.04",
        "cursorShape": "filledBox" // or put this in your 
    },
    

    Remember, that wsl.exe ~ -d Ubuntu18.04 should use whatever your actual instance name is from the wsl -l -v we did before.

    The (undocumented, as far as I can tell) ~, of course, tells it to start in your home directory. You could also use the wsl.exe --cd argument, but it requires a Windows path, so it would have to be something like wsl.exe --cd "\\wsl$\Ubuntu18.04\home\username".

  • Now Windows Terminal should launch your instance into your home directory.

  • Since it sounds like you already have that profile set as your default, you can just pin Windows Terminal to the Taskbar and launch it now, and you should be good.

  • But if you had a different profile that you wanted to be the default, you can still launch Windows Terminal using wt.exe -p Ubuntu18.04 (or whatever the profile "name" is in your settings.json).

6
  • Thank you for the detailed answer! The profiles seem intuitive enough, however, I would also want to both be able to run the taskbar Terminal and have it take me to /home/$USER, but also be able to use the right-click -> "Open Windows Terminal " functionality in any folder and have it take me there! After following your advice, I can either have the Terminal take me to /home/$USER always, or e.g. using "commandline": "wsl.exe -d Ubuntu-18.04", be able to right-click and open WSL in any directory but the taskbar app takes me to /mnt/c/Users/<user>. Could I have the best of both worlds? Commented Mar 5, 2021 at 8:36
  • A simple hack could be to add if $PWD = "/mnt/c/Users/<user>" to .profile... Commented Mar 5, 2021 at 9:23
  • Hmm - I don't have a right-click "Open Windows Terminal" (either in latest release or latest Preview). I only have Shift Right-click "Open Linux shell here". Also, is the commandline a typo? You mention "commandline": "wsl.exe -d Ubuntu-18.04", but it should be "commandline": "wsl.exe ~ -d Ubuntu-18.04", right? Commented Mar 5, 2021 at 21:41
  • Not a typo! With ~, it overrides everything and takes me to /home/$USER. Without it, it just opens the WSL, taking me to /mnt/c/Users/kark if run from the taskbar, or wherever the right-click happened if done with right-click. The "Open Windows terminal here" could be a remnant of a registry edit, but I thought I removed that one completely. Commented Mar 6, 2021 at 8:48
  • Ah, I figured out why I wasn't seeing "Open in windows terminal". It's apparently been there since release 1.1 last June or so. I see from the PR in Github that it simply uses the default profile, but we should be able to edit the registry entry for it to override that. I'll play with that in a bit ... Commented Mar 6, 2021 at 14:32

You must log in to answer this question.

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