A little tip, partly written for the benefit of future-me…
As you may know, WSL2 filesystem performance is much improved over its predecessor – but only in the virtual disk of your Linux distro. The mounted Windows disk – /mnt/c/ – is still slow for disk-heavy operations, like Git clones, because of Linux-plus-NTFS something reasons.
Because of this, the first thing I do when I open my WSL2 Ubuntu distro in Windows Terminal is change to my Linux home directory. Every time.
There must be an easier way? Yep.
From the WSL docs:
bash ~
launches the bash shell into the user’s home directory. Similar to runningcd ~
.
To make this the default in Windows Terminal, open the Windows Terminal Settings, find your WSL2 profile, and add “commandline”: “bash.exe ~”
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"commandline": "bash.exe ~"
}
(Note that the “source” line now needs a trailing comma.)
From this:
To this:
You can also use startingDirectory property on profile as shown in https://docs.microsoft.com/et-ee/windows/terminal/troubleshooting#set-your-wsl-distribution-to-start-in-the-home–directory-when-launched
my setting looks like
“name”: “Ubuntu”,
“source”: “Windows.Terminal.Wsl”,
“startingDirectory”: “//wsl$/Ubuntu/home/”
Thank you! Great solution and very easy to follow.
Thanks for the pointer, Dan!
I use multiple distributions with WSL (Ubuntu for dev, Debian for test), so I need to launch with wsl.exe -d I found out (wsl –help) that wsl.exe has a parameter to cd after launch. My Windows Terminal commandline is now ‘wsl -d Ubuntu –cd ~’ and the startingDirectory attribute is left blank.
Thanks for the tip Tim. Just emphasizing as was not well formatted in your comment, its a double hyphen before the cd: wsl -d Ubuntu –cd ~
and in my comment above happened the same (the comment system of the blog replaced the double hyphen by a long dash which in a copy and paste will make it fail … just be all advised to replace it 🙂