mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Host: detect WSL version
This commit is contained in:
@@ -5,9 +5,6 @@
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_HOST_PRODUCT_NAME_WSL "Windows Subsystem for Linux"
|
||||
#define FF_HOST_PRODUCT_NAME_MSYS "Windows on MSYS"
|
||||
|
||||
typedef struct FFHostResult
|
||||
{
|
||||
FFstrbuf productFamily;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "host.h"
|
||||
#include "common/io.h"
|
||||
#include "common/processing.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -94,6 +95,27 @@ void ffDetectHostImpl(FFHostResult* host)
|
||||
{
|
||||
//On WSL, the real host can't be detected. Instead use WSL as host.
|
||||
if(getenv("WSL_DISTRO") != NULL || getenv("WSL_INTEROP") != NULL)
|
||||
ffStrbufAppendS(&host->productName, FF_HOST_PRODUCT_NAME_WSL);
|
||||
{
|
||||
ffStrbufAppendS(&host->productName, "Windows Subsystem for Linux");
|
||||
|
||||
FFstrbuf wslVer; //Wide charactors
|
||||
ffStrbufInit(&wslVer);
|
||||
if(!ffProcessAppendStdOut(&wslVer, (char* const[]){
|
||||
"wsl.exe",
|
||||
"--version",
|
||||
NULL
|
||||
}) && wslVer.length > 0)
|
||||
{
|
||||
ffStrbufSubstrBeforeFirstC(&wslVer, '\r'); //CRLF
|
||||
ffStrbufSubstrAfterLastC(&wslVer, ' ');
|
||||
ffStrbufAppendS(&host->productName, " (");
|
||||
for(uint32_t i = 0; i < wslVer.length; ++i) {
|
||||
if(wslVer.chars[i]) //don't append \0
|
||||
ffStrbufAppendC(&host->productName, wslVer.chars[i]);
|
||||
}
|
||||
ffStrbufAppendC(&host->productName, ')');
|
||||
}
|
||||
ffStrbufDestroy(&wslVer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "fastfetch.h"
|
||||
#include "detection/host/host.h"
|
||||
#include "common/io.h"
|
||||
#include "common/parsing.h"
|
||||
#include "common/processing.h"
|
||||
@@ -239,10 +238,8 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
|
||||
if(!ffStrSet(term))
|
||||
{
|
||||
//We are in WSL but not in Windows Terminal
|
||||
const FFHostResult* host = ffDetectHost();
|
||||
if(ffStrbufCompS(&host->productName, FF_HOST_PRODUCT_NAME_WSL) == 0 ||
|
||||
ffStrbufCompS(&host->productName, FF_HOST_PRODUCT_NAME_MSYS) == 0) //TODO better WSL or MSYS detection
|
||||
term = "conhost";
|
||||
if(getenv("WSL_DISTRO") != NULL || getenv("WSL_INTEROP") != NULL)
|
||||
term = "conhost";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user