DEV Community

Cover image for WSL2 with Windows Terminal
Jim Frenette
Jim Frenette

Posted on • Originally published at jimfrenette.com

WSL2 with Windows Terminal

Windows has finally created a developer command line experience that can compete with OS X and bare metal Linux with the release of WSL2 combined with the new Windows Terminal. For WSL2 installion and updates, refer to the official Windows Subsystem for Linux Documentation.

Free your mind of an inferior Windows developer experience and make the jump

The following has been tested on Windows 10 build 19041 with WSL2 enabled and set as the default version.
Additionally,

Windows Terminal

One of the things I really like about the new Windows Terminal is the cut, copy and paste keybindings. No more Ctrl+Shift needed, just use Ctrl+V to paste. For example, here are some snippets from my terminal settings.json.

settings.json
...

// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": true,

// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,

// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
//   and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles":
{
  "defaults": {
    // Put settings here that you want to apply to all profiles.
    "fontSize": 11
  },
  ...
}

...

// Add custom keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about keybindings, visit https://aka.ms/terminal-keybindings
"keybindings":
[
    // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
    // These two lines additionally bind them to Ctrl+C and Ctrl+V.
    // To learn more about selection, visit https://aka.ms/terminal-selection
    { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
    { "command": "paste", "keys": "ctrl+v" },

    // Press Ctrl+Shift+F to open the search box
    { "command": "find", "keys": "ctrl+shift+f" },

    // Press Alt+Shift+D to open a new pane.
    // - "split": "auto" makes this pane open in the direction that provides the most surface area.
    // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
    // To learn more about panes, visit https://aka.ms/terminal-panes
    { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
]

Oh My Zsh

One of the first things I do when setting up a new bash shell is install zsh and Oh My Zsh.

If you're an npm user, I reccommend installing nvm as an Oh My ZSH! custom plugin by cloning zsh-nvm into your custom plugins repo as follows:

cd ~/.oh-my-zsh/custom/plugins

git clone https://github.com/lukechilds/zsh-nvm

Then load as a plugin in your ~/.zshrc profile. Note that plugins need to be added before oh-my-zsh.sh is sourced.

.zshrc
...

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
 git
 zsh-nvm
)

source $ZSH/oh-my-zsh.sh

Additionally, if you're using Java and Maven, you can install and run those from WSL2 to build projects even if they exist on the mounted native Windows file system.

For example, I use SDKMAN! to manage mutiple JDK versions similar to how I manage multiple node versions using nvm.

WSL windows terminal example of mvn --version

Explorer

WSL Ubuntu Files in Windows Explorer

Access your WSL files in Explorer by entering network path \\wsl$ in the address bar.

Resources

Originally posted at jimfrenette.com/2020/07/wsl2-windows-terminal

Top comments (4)

Collapse
 
manuelojeda profile image
Manuel Ojeda

I have been working with WSL 2 since the official release and I can assure you that I don't miss working with native Ubuntu and of course using a Dual Boot in my PC.

This is a huge step from Microsoft 🥳

Collapse
 
habereder profile image
Raphael Habereder

WSL1 was already a huge step up for MS in my opinion. It just worked and for a change I didn't have to completely rework my Linux workflow.

I'm so excited to tinker with wsl2 once it goes GA, I can only imagine how much better it is having a REAL linux to work with in parallel :)

Collapse
 
jimfrenette profile image
Jim Frenette

Hey Raphael, good news - WSL2 is GA as of the update in May, blogs.windows.com/windowsexperienc...

That is actually when I first started using it. I have since reduced the size of my fedora 32 partition I was primarily developing on and now use Windows more often.

Collapse
 
habereder profile image
Raphael Habereder

Interesting, I thought the update has been pushed back, due to the frequent problems MS had the last couple of big updates. I'll make sure to investigate and upgrade asap, thanks for the heads-up!