Windows Subsystem for Linux (WSL) provides a powerful environment for running Linux distributions on Windows. If you're a fan of the Debian distribution and use Windows Terminal, you might want to streamline your workflow by automatically starting tmux every time you launch a new Debian tab.

Given that instead of launching the default shell, tmux is executed...

  • if you detach the tmux session the tab is closed
  • if you close the tab or the windows terminal without detaching the tmux session, that sessions remains opened.

That's why i prefer to create a duplicated profile so i get a profile that launches tmux and another one that launches default shell.

It's worth noting that a configuration like this can be easily extrapolated to other Linux distributions within WSL. In this guide, we'll walk through the steps to achieve this setup.

Checking and Installing tmux

Before configuring Windows Terminal, ensure that tmux is installed in your Linux distribution. Open a terminal window and run the following commands (applies to distributions using apt/deb packages):

sudo apt update
sudo apt install tmux


These commands ensure that your Debian environment has tmux installed. If it's already installed, the system will be updated to the latest version.

Configuring Windows Terminal

Open Windows Terminal and navigate to the "Settings" and press "+ Add a new profile" option

Modify the name (in this example i modified "Debian" to "Debian (TMUX)"

In the "Command line" field, you will likely be able to see something like this:

C:\Windows\System32\wsl.exe -d Debian

Add the parameter "-e tmux new" so the command becomes

C:\Windows\System32\wsl.exe -d Debian -e tmux new

Save the changes

Testing the Setup

Now, each time you open a new Linux tab in Windows Terminal, you can choose either the standard one that opens the default shell, or the one in which tmux should automatically launch, providing you with a powerful terminal multiplexer for managing multiple sessions and windows.

Each tmux tab will be attached to a different tmux sessión.

Conclusion

Configuring Windows Terminal to start tmux automatically with your WSL Linux distribution tab enhances your productivity by eliminating the need to manually initiate tmux each time. Ensure that tmux is installed and up-to-date in your environment, and then follow the steps above to set up the automatic tmux startup. This configuration can be extrapolated to other Linux distributions within WSL, allowing you to customize your environment based on your distribution of choice.