go-task / task

A task runner / simpler Make alternative written in Go
https://taskfile.dev
MIT License
11.01k stars 584 forks source link

feat: add `isWSL` function to detect if Task is being ran on WSL #1731

Open ssbarnea opened 1 month ago

ssbarnea commented 1 month ago

It seems that the platform is evaluated as "linux" instead of "windows" or at least something as "wsl" when you run taskfile on windows under wsl.

I am not totally surprised by this but it is still incorrect as it does not allow us to properly identify windows platform when we executed commands under wsl (we are forced to do that due to the build chain).

andreynering commented 1 month ago

Hey @ssbarnea,

Can we reliably detect that a Linux binary is ran under WSL? If so, we can consider adding another template function.

I wouldn't change the {{OS}} function because, tecnically, it is running on Linux because WSL is Linux, and I'm certain people rely on the current behavior. If we changed it to return windows it would break people's Taskfiles.

andreynering commented 1 month ago

We can get some inspiration from https://github.com/scivision/detect-windows-subsystem-for-linux

There's potential to publish this on a standalone Go package on its own repository, so other people can benefit from it.

vmaerten commented 1 month ago

I like the idea @andreynering

alexhampu commented 1 month ago

This is something that will come really useful to support Windows devices as well as Linux and Mac, without fully rewriting a lot of task commands to use Powershell.