mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-07 05:34:20 +01:00
Chore: run clang-format
```bash find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) ! -path "src/3rdparty/*" -print0 | xargs -0 clang-format -i ```
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -4,12 +4,11 @@
|
||||
#include "modules/terminal/option.h"
|
||||
#include "modules/shell/option.h"
|
||||
|
||||
typedef struct FFShellResult
|
||||
{
|
||||
typedef struct FFShellResult {
|
||||
FFstrbuf processName;
|
||||
FFstrbuf exe; //Actually arg0 in *nix
|
||||
const char* exeName; //pointer to a char in exe
|
||||
FFstrbuf exePath; //Full real path to executable file
|
||||
FFstrbuf exe; // Actually arg0 in *nix
|
||||
const char* exeName; // pointer to a char in exe
|
||||
FFstrbuf exePath; // Full real path to executable file
|
||||
FFstrbuf prettyName;
|
||||
FFstrbuf version;
|
||||
uint32_t pid;
|
||||
@@ -17,13 +16,12 @@ typedef struct FFShellResult
|
||||
int32_t tty;
|
||||
} FFShellResult;
|
||||
|
||||
typedef struct FFTerminalResult
|
||||
{
|
||||
typedef struct FFTerminalResult {
|
||||
FFstrbuf processName;
|
||||
FFstrbuf exe;
|
||||
FFstrbuf prettyName;
|
||||
const char* exeName; //pointer to a char in exe
|
||||
FFstrbuf exePath; //Full real path to executable file
|
||||
const char* exeName; // pointer to a char in exe
|
||||
FFstrbuf exePath; // Full real path to executable file
|
||||
FFstrbuf version;
|
||||
FFstrbuf tty;
|
||||
uint32_t pid;
|
||||
|
||||
@@ -9,62 +9,58 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void setExeName(FFstrbuf* exe, const char** exeName)
|
||||
{
|
||||
static void setExeName(FFstrbuf* exe, const char** exeName) {
|
||||
assert(exe->length > 0);
|
||||
uint32_t lastSlashIndex = ffStrbufLastIndexC(exe, '/');
|
||||
if(lastSlashIndex < exe->length)
|
||||
if (lastSlashIndex < exe->length) {
|
||||
*exeName = exe->chars + lastSlashIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static pid_t getShellInfo(FFShellResult* result, pid_t pid)
|
||||
{
|
||||
static pid_t getShellInfo(FFShellResult* result, pid_t pid) {
|
||||
pid_t ppid = 0;
|
||||
int32_t tty = -1;
|
||||
|
||||
const char* userShellName = NULL;
|
||||
{
|
||||
uint32_t index = ffStrbufLastIndexC(&instance.state.platform.userShell, '/');
|
||||
if (index == instance.state.platform.userShell.length)
|
||||
if (index == instance.state.platform.userShell.length) {
|
||||
userShellName = instance.state.platform.userShell.chars;
|
||||
else
|
||||
} else {
|
||||
userShellName = instance.state.platform.userShell.chars + index + 1;
|
||||
}
|
||||
}
|
||||
|
||||
while (pid > 1 && ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, &tty) == NULL)
|
||||
{
|
||||
if (!ffStrbufEqualS(&result->processName, userShellName))
|
||||
{
|
||||
//Common programs that are between terminal and own process, but are not the shell
|
||||
if(
|
||||
while (pid > 1 && ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, &tty) == NULL) {
|
||||
if (!ffStrbufEqualS(&result->processName, userShellName)) {
|
||||
// Common programs that are between terminal and own process, but are not the shell
|
||||
if (
|
||||
// tty < 0 || //A shell should connect to a tty
|
||||
pid == 1 || // init/systemd
|
||||
ffStrbufEqualS(&result->processName, "sh") || //This prevents us from detecting things like pipes and redirects, i hope nobody uses plain `sh` as shell
|
||||
ffStrbufEqualS(&result->processName, "sudo") ||
|
||||
ffStrbufEqualS(&result->processName, "su") ||
|
||||
ffStrbufEqualS(&result->processName, "strace") ||
|
||||
ffStrbufEqualS(&result->processName, "gdb") ||
|
||||
ffStrbufEqualS(&result->processName, "lldb") ||
|
||||
ffStrbufEqualS(&result->processName, "lldb-mi") ||
|
||||
ffStrbufEqualS(&result->processName, "login") ||
|
||||
ffStrbufEqualS(&result->processName, "ltrace") ||
|
||||
ffStrbufEqualS(&result->processName, "perf") ||
|
||||
ffStrbufEqualS(&result->processName, "guake-wrapped") ||
|
||||
ffStrbufEqualS(&result->processName, "time") ||
|
||||
ffStrbufEqualS(&result->processName, "clifm") || //https://github.com/leo-arch/clifm/issues/289
|
||||
ffStrbufEqualS(&result->processName, "valgrind") ||
|
||||
ffStrbufEqualS(&result->processName, "fastfetch") || //#994
|
||||
ffStrbufEqualS(&result->processName, "flashfetch") ||
|
||||
ffStrbufEqualS(&result->processName, "proot") ||
|
||||
ffStrbufEqualS(&result->processName, "script") ||
|
||||
#ifdef __linux__
|
||||
ffStrbufEqualS(&result->processName, "run-parts") ||
|
||||
#endif
|
||||
ffStrbufContainS(&result->processName, "debug") ||
|
||||
ffStrbufContainS(&result->processName, "command-not-") ||
|
||||
ffStrbufEndsWithS(&result->processName, ".sh")
|
||||
)
|
||||
{
|
||||
pid == 1 || // init/systemd
|
||||
ffStrbufEqualS(&result->processName, "sh") || // This prevents us from detecting things like pipes and redirects, i hope nobody uses plain `sh` as shell
|
||||
ffStrbufEqualS(&result->processName, "sudo") ||
|
||||
ffStrbufEqualS(&result->processName, "su") ||
|
||||
ffStrbufEqualS(&result->processName, "strace") ||
|
||||
ffStrbufEqualS(&result->processName, "gdb") ||
|
||||
ffStrbufEqualS(&result->processName, "lldb") ||
|
||||
ffStrbufEqualS(&result->processName, "lldb-mi") ||
|
||||
ffStrbufEqualS(&result->processName, "login") ||
|
||||
ffStrbufEqualS(&result->processName, "ltrace") ||
|
||||
ffStrbufEqualS(&result->processName, "perf") ||
|
||||
ffStrbufEqualS(&result->processName, "guake-wrapped") ||
|
||||
ffStrbufEqualS(&result->processName, "time") ||
|
||||
ffStrbufEqualS(&result->processName, "clifm") || // https://github.com/leo-arch/clifm/issues/289
|
||||
ffStrbufEqualS(&result->processName, "valgrind") ||
|
||||
ffStrbufEqualS(&result->processName, "fastfetch") || // #994
|
||||
ffStrbufEqualS(&result->processName, "flashfetch") ||
|
||||
ffStrbufEqualS(&result->processName, "proot") ||
|
||||
ffStrbufEqualS(&result->processName, "script") ||
|
||||
#ifdef __linux__
|
||||
ffStrbufEqualS(&result->processName, "run-parts") ||
|
||||
#endif
|
||||
ffStrbufContainS(&result->processName, "debug") ||
|
||||
ffStrbufContainS(&result->processName, "command-not-") ||
|
||||
ffStrbufEndsWithS(&result->processName, ".sh")) {
|
||||
pid = ppid;
|
||||
ffStrbufClear(&result->processName);
|
||||
continue;
|
||||
@@ -80,69 +76,66 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid)
|
||||
return pid > 1 ? ppid : 0;
|
||||
}
|
||||
|
||||
static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid)
|
||||
{
|
||||
static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) {
|
||||
pid_t ppid = 0;
|
||||
|
||||
while (pid > 1 && ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, NULL) == NULL)
|
||||
{
|
||||
//Known shells
|
||||
while (pid > 1 && ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, NULL) == NULL) {
|
||||
// Known shells
|
||||
if (
|
||||
pid == 1 || // init/systemd
|
||||
ffStrbufEqualS(&result->processName, "sudo") ||
|
||||
ffStrbufEqualS(&result->processName, "su") ||
|
||||
ffStrbufEqualS(&result->processName, "sh") ||
|
||||
ffStrbufEqualS(&result->processName, "ash") ||
|
||||
ffStrbufEqualS(&result->processName, "bash") ||
|
||||
ffStrbufEqualS(&result->processName, "zsh") ||
|
||||
ffStrbufEqualS(&result->processName, "ksh") ||
|
||||
ffStrbufEqualS(&result->processName, "mksh") ||
|
||||
ffStrbufEqualS(&result->processName, "oksh") ||
|
||||
ffStrbufEqualS(&result->processName, "csh") ||
|
||||
ffStrbufEqualS(&result->processName, "tcsh") ||
|
||||
ffStrbufEqualS(&result->processName, "fish") ||
|
||||
ffStrbufEqualS(&result->processName, "dash") ||
|
||||
ffStrbufEqualS(&result->processName, "pwsh") ||
|
||||
ffStrbufEqualS(&result->processName, "nu") ||
|
||||
ffStrbufEqualS(&result->processName, "git-shell") ||
|
||||
ffStrbufEqualS(&result->processName, "elvish") ||
|
||||
ffStrbufEqualS(&result->processName, "oil.ovm") ||
|
||||
ffStrbufEqualS(&result->processName, "xonsh") || // works in Linux but not in macOS because kernel returns `Python` in this case
|
||||
ffStrbufEqualS(&result->processName, "login") ||
|
||||
ffStrbufEqualS(&result->processName, "clifm") || // https://github.com/leo-arch/clifm/issues/289
|
||||
ffStrbufEqualS(&result->processName, "chezmoi") || // #762
|
||||
ffStrbufEqualS(&result->processName, "proot") ||
|
||||
ffStrbufEqualS(&result->processName, "script") ||
|
||||
#ifdef __linux__
|
||||
ffStrbufStartsWithS(&result->processName, "Relay(") || // Unknown process in WSL2
|
||||
ffStrbufEqualS(&result->processName, "sudo") ||
|
||||
ffStrbufEqualS(&result->processName, "su") ||
|
||||
ffStrbufEqualS(&result->processName, "sh") ||
|
||||
ffStrbufEqualS(&result->processName, "ash") ||
|
||||
ffStrbufEqualS(&result->processName, "bash") ||
|
||||
ffStrbufEqualS(&result->processName, "zsh") ||
|
||||
ffStrbufEqualS(&result->processName, "ksh") ||
|
||||
ffStrbufEqualS(&result->processName, "mksh") ||
|
||||
ffStrbufEqualS(&result->processName, "oksh") ||
|
||||
ffStrbufEqualS(&result->processName, "csh") ||
|
||||
ffStrbufEqualS(&result->processName, "tcsh") ||
|
||||
ffStrbufEqualS(&result->processName, "fish") ||
|
||||
ffStrbufEqualS(&result->processName, "dash") ||
|
||||
ffStrbufEqualS(&result->processName, "pwsh") ||
|
||||
ffStrbufEqualS(&result->processName, "nu") ||
|
||||
ffStrbufEqualS(&result->processName, "git-shell") ||
|
||||
ffStrbufEqualS(&result->processName, "elvish") ||
|
||||
ffStrbufEqualS(&result->processName, "oil.ovm") ||
|
||||
ffStrbufEqualS(&result->processName, "xonsh") || // works in Linux but not in macOS because kernel returns `Python` in this case
|
||||
ffStrbufEqualS(&result->processName, "login") ||
|
||||
ffStrbufEqualS(&result->processName, "clifm") || // https://github.com/leo-arch/clifm/issues/289
|
||||
ffStrbufEqualS(&result->processName, "chezmoi") || // #762
|
||||
ffStrbufEqualS(&result->processName, "proot") ||
|
||||
ffStrbufEqualS(&result->processName, "script") ||
|
||||
#ifdef __linux__
|
||||
ffStrbufStartsWithS(&result->processName, "Relay(") || // Unknown process in WSL2
|
||||
ffStrbufStartsWithS(&result->processName, "flatpak-") || // #707
|
||||
ffStrbufEqualS(&result->processName, "run-parts") || // #2048
|
||||
#endif
|
||||
ffStrbufEndsWithS(&result->processName, ".sh")
|
||||
)
|
||||
{
|
||||
ffStrbufEqualS(&result->processName, "run-parts") || // #2048
|
||||
#endif
|
||||
ffStrbufEndsWithS(&result->processName, ".sh")) {
|
||||
pid = ppid;
|
||||
ffStrbufClear(&result->processName);
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
#ifdef __APPLE__
|
||||
// https://github.com/fastfetch-cli/fastfetch/discussions/501
|
||||
const char* pLeft = strstr(result->processName.chars, " (");
|
||||
if (pLeft)
|
||||
{
|
||||
if (pLeft) {
|
||||
pLeft += 2;
|
||||
const char* pRight = strstr(pLeft, "term)");
|
||||
if (pRight && pRight[5] == '\0')
|
||||
{
|
||||
for (; pLeft < pRight; ++pLeft)
|
||||
if (*pLeft < 'a' || *pLeft > 'z')
|
||||
if (pRight && pRight[5] == '\0') {
|
||||
for (; pLeft < pRight; ++pLeft) {
|
||||
if (*pLeft < 'a' || *pLeft > 'z') {
|
||||
break;
|
||||
if (pLeft == pRight && ffProcessGetBasicInfoLinux(ppid, &result->processName, &ppid, NULL) != NULL)
|
||||
}
|
||||
}
|
||||
if (pLeft == pRight && ffProcessGetBasicInfoLinux(ppid, &result->processName, &ppid, NULL) != NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
result->pid = (uint32_t) pid;
|
||||
result->ppid = (uint32_t) ppid;
|
||||
@@ -152,16 +145,15 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid)
|
||||
return pid > 1 ? ppid : 0;
|
||||
}
|
||||
|
||||
static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv)
|
||||
{
|
||||
static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv) {
|
||||
const char* envStr = getenv(pidEnv);
|
||||
if (envStr == NULL)
|
||||
if (envStr == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pid_t pid = (pid_t) strtol(envStr, NULL, 10);
|
||||
result->pid = (uint32_t) pid;
|
||||
if (ffProcessGetBasicInfoLinux(pid, &result->processName, (pid_t*) &result->ppid, NULL) == NULL)
|
||||
{
|
||||
if (ffProcessGetBasicInfoLinux(pid, &result->processName, (pid_t*) &result->ppid, NULL) == NULL) {
|
||||
ffProcessGetInfoLinux(pid, &result->processName, &result->exe, &result->exeName, &result->exePath);
|
||||
return true;
|
||||
}
|
||||
@@ -169,24 +161,22 @@ static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv
|
||||
return false;
|
||||
}
|
||||
|
||||
static void getTerminalFromEnv(FFTerminalResult* result)
|
||||
{
|
||||
if (result->processName.length > 0)
|
||||
{
|
||||
static void getTerminalFromEnv(FFTerminalResult* result) {
|
||||
if (result->processName.length > 0) {
|
||||
if (!ffStrbufStartsWithS(&result->processName, "login") &&
|
||||
!ffStrbufEqualS(&result->processName, "(login)") &&
|
||||
|
||||
#ifdef __APPLE__
|
||||
#ifdef __APPLE__
|
||||
!ffStrbufEqualS(&result->processName, "launchd") &&
|
||||
#else
|
||||
#else
|
||||
!ffStrbufEqualS(&result->processName, "systemd") &&
|
||||
!ffStrbufEqualS(&result->processName, "init") &&
|
||||
!ffStrbufEqualS(&result->processName, "(init)") &&
|
||||
!ffStrbufEqualS(&result->processName, "SessionLeader") && // #750
|
||||
#endif
|
||||
#endif
|
||||
|
||||
!ffStrbufEqualS(&result->processName, "0")
|
||||
) return;
|
||||
!ffStrbufEqualS(&result->processName, "0"))
|
||||
return;
|
||||
|
||||
ffStrbufClear(&result->processName);
|
||||
ffStrbufClear(&result->exe);
|
||||
@@ -197,95 +187,93 @@ static void getTerminalFromEnv(FFTerminalResult* result)
|
||||
|
||||
const char* term = NULL;
|
||||
|
||||
//SSH
|
||||
if(
|
||||
getenv("SSH_TTY") != NULL
|
||||
)
|
||||
// SSH
|
||||
if (
|
||||
getenv("SSH_TTY") != NULL) {
|
||||
term = getenv("SSH_TTY");
|
||||
else if(
|
||||
} else if (
|
||||
getenv("KITTY_PID") != NULL ||
|
||||
getenv("KITTY_INSTALLATION_DIR") != NULL
|
||||
)
|
||||
{
|
||||
if (getTerminalInfoByPidEnv(result, "KITTY_PID"))
|
||||
getenv("KITTY_INSTALLATION_DIR") != NULL) {
|
||||
if (getTerminalInfoByPidEnv(result, "KITTY_PID")) {
|
||||
return;
|
||||
}
|
||||
term = "kitty";
|
||||
}
|
||||
|
||||
#ifdef __linux__ // WSL
|
||||
//Windows Terminal
|
||||
else if(
|
||||
#ifdef __linux__ // WSL
|
||||
// Windows Terminal
|
||||
else if (
|
||||
getenv("WT_SESSION") != NULL ||
|
||||
getenv("WT_PROFILE_ID") != NULL
|
||||
) term = "Windows Terminal";
|
||||
getenv("WT_PROFILE_ID") != NULL)
|
||||
term = "Windows Terminal";
|
||||
|
||||
//ConEmu
|
||||
else if(
|
||||
getenv("ConEmuPID") != NULL
|
||||
) term = "ConEmu";
|
||||
#endif
|
||||
// ConEmu
|
||||
else if (
|
||||
getenv("ConEmuPID") != NULL) {
|
||||
term = "ConEmu";
|
||||
}
|
||||
#endif
|
||||
|
||||
//Alacritty
|
||||
else if(
|
||||
// Alacritty
|
||||
else if (
|
||||
getenv("ALACRITTY_SOCKET") != NULL ||
|
||||
getenv("ALACRITTY_LOG") != NULL ||
|
||||
getenv("ALACRITTY_WINDOW_ID") != NULL
|
||||
) term = "Alacritty";
|
||||
|
||||
#ifdef __ANDROID__
|
||||
//Termux
|
||||
else if(
|
||||
getenv("ALACRITTY_WINDOW_ID") != NULL) {
|
||||
term = "Alacritty";
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
// Termux
|
||||
else if (
|
||||
getenv("TERMUX_VERSION") != NULL ||
|
||||
getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL
|
||||
)
|
||||
{
|
||||
if (getTerminalInfoByPidEnv(result, "TERMUX_APP__PID"))
|
||||
getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL) {
|
||||
if (getTerminalInfoByPidEnv(result, "TERMUX_APP__PID")) {
|
||||
return;
|
||||
}
|
||||
term = "com.termux";
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__GNU__)
|
||||
//Konsole
|
||||
else if(
|
||||
getenv("KONSOLE_VERSION") != NULL
|
||||
) term = "konsole";
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__GNU__)
|
||||
// Konsole
|
||||
else if (
|
||||
getenv("KONSOLE_VERSION") != NULL)
|
||||
term = "konsole";
|
||||
|
||||
else if(
|
||||
else if (
|
||||
getenv("GNOME_TERMINAL_SCREEN") != NULL ||
|
||||
getenv("GNOME_TERMINAL_SERVICE") != NULL
|
||||
) term = "gnome-terminal";
|
||||
#endif
|
||||
getenv("GNOME_TERMINAL_SERVICE") != NULL) {
|
||||
term = "gnome-terminal";
|
||||
}
|
||||
#endif
|
||||
|
||||
//MacOS, mintty
|
||||
else if(getenv("TERM_PROGRAM") != NULL)
|
||||
// MacOS, mintty
|
||||
else if (getenv("TERM_PROGRAM") != NULL) {
|
||||
term = getenv("TERM_PROGRAM");
|
||||
|
||||
else if(getenv("LC_TERMINAL") != NULL)
|
||||
term = getenv("LC_TERMINAL");
|
||||
|
||||
//Normal Terminal
|
||||
else
|
||||
{
|
||||
term = getenv("TERM");
|
||||
//TTY
|
||||
if(!ffStrSet(term) || ffStrEquals(term, "linux"))
|
||||
term = ttyname(STDIN_FILENO);
|
||||
}
|
||||
|
||||
if(ffStrSet(term))
|
||||
{
|
||||
else if (getenv("LC_TERMINAL") != NULL) {
|
||||
term = getenv("LC_TERMINAL");
|
||||
}
|
||||
|
||||
// Normal Terminal
|
||||
else {
|
||||
term = getenv("TERM");
|
||||
// TTY
|
||||
if (!ffStrSet(term) || ffStrEquals(term, "linux")) {
|
||||
term = ttyname(STDIN_FILENO);
|
||||
}
|
||||
}
|
||||
|
||||
if (ffStrSet(term)) {
|
||||
ffStrbufSetS(&result->processName, term);
|
||||
ffStrbufSetS(&result->exe, term);
|
||||
setExeName(&result->exe, &result->exeName);
|
||||
}
|
||||
}
|
||||
|
||||
static void getUserShellFromEnv(FFShellResult* result)
|
||||
{
|
||||
//If shell detection via processes failed
|
||||
if(result->processName.length == 0 && instance.state.platform.userShell.length > 0)
|
||||
{
|
||||
static void getUserShellFromEnv(FFShellResult* result) {
|
||||
// If shell detection via processes failed
|
||||
if (result->processName.length == 0 && instance.state.platform.userShell.length > 0) {
|
||||
ffStrbufSet(&result->exe, &instance.state.platform.userShell);
|
||||
setExeName(&result->exe, &result->exeName);
|
||||
ffStrbufAppendS(&result->processName, result->exeName);
|
||||
@@ -296,115 +284,109 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
|
||||
|
||||
static void setShellInfoDetails(FFShellResult* result)
|
||||
{
|
||||
static void setShellInfoDetails(FFShellResult* result) {
|
||||
ffStrbufClear(&result->version);
|
||||
fftsGetShellVersion(result->exePath.length > 0 ? &result->exePath : &result->exe, result->exeName, &result->version);
|
||||
|
||||
if(ffStrbufEqualS(&result->processName, "pwsh"))
|
||||
if (ffStrbufEqualS(&result->processName, "pwsh")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "PowerShell");
|
||||
else if(ffStrbufEqualS(&result->processName, "nu"))
|
||||
} else if (ffStrbufEqualS(&result->processName, "nu")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "nushell");
|
||||
else if(ffStrbufEqualS(&result->processName, "oil.ovm"))
|
||||
} else if (ffStrbufEqualS(&result->processName, "oil.ovm")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "Oils");
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// https://github.com/fastfetch-cli/fastfetch/discussions/280#discussioncomment-3831734
|
||||
ffStrbufInitS(&result->prettyName, result->exeName);
|
||||
}
|
||||
}
|
||||
|
||||
static void setTerminalInfoDetails(FFTerminalResult* result)
|
||||
{
|
||||
if(ffStrbufStartsWithC(&result->processName, '.') && ffStrbufContainS(&result->processName, "-wrap"))
|
||||
{
|
||||
static void setTerminalInfoDetails(FFTerminalResult* result) {
|
||||
if (ffStrbufStartsWithC(&result->processName, '.') && ffStrbufContainS(&result->processName, "-wrap")) {
|
||||
// For NixOS. Ref: #510 and https://github.com/NixOS/nixpkgs/pull/249428
|
||||
// We use processName when detecting version and font, overriding it for simplification
|
||||
ffStrbufSubstrBeforeLastC(&result->processName, '-');
|
||||
ffStrbufSubstrAfter(&result->processName, 0);
|
||||
}
|
||||
|
||||
if(ffStrbufEqualS(&result->processName, "wezterm-gui"))
|
||||
if (ffStrbufEqualS(&result->processName, "wezterm-gui")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "WezTerm");
|
||||
else if(ffStrbufStartsWithS(&result->processName, "tmux:"))
|
||||
} else if (ffStrbufStartsWithS(&result->processName, "tmux:")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "tmux");
|
||||
else if(ffStrbufStartsWithS(&result->processName, "screen-"))
|
||||
} else if (ffStrbufStartsWithS(&result->processName, "screen-")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "screen");
|
||||
else if(ffStrbufEqualS(&result->processName, "sshd") || ffStrbufStartsWithS(&result->processName, "sshd-"))
|
||||
{
|
||||
if (result->tty.length)
|
||||
} else if (ffStrbufEqualS(&result->processName, "sshd") || ffStrbufStartsWithS(&result->processName, "sshd-")) {
|
||||
if (result->tty.length) {
|
||||
ffStrbufInitCopy(&result->prettyName, &result->tty);
|
||||
else
|
||||
} else {
|
||||
ffStrbufSetStatic(&result->prettyName, "sshd");
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#if defined(__ANDROID__)
|
||||
|
||||
else if(ffStrbufEqualS(&result->processName, "com.termux"))
|
||||
else if (ffStrbufEqualS(&result->processName, "com.termux"))
|
||||
ffStrbufInitStatic(&result->prettyName, "Termux");
|
||||
|
||||
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__GNU__)
|
||||
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__GNU__)
|
||||
|
||||
else if(ffStrbufStartsWithS(&result->processName, "gnome-terminal"))
|
||||
else if (ffStrbufStartsWithS(&result->processName, "gnome-terminal"))
|
||||
ffStrbufInitStatic(&result->prettyName, "GNOME Terminal");
|
||||
else if(ffStrbufStartsWithS(&result->processName, "kgx"))
|
||||
else if (ffStrbufStartsWithS(&result->processName, "kgx")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "GNOME Console");
|
||||
else if(ffStrbufEqualS(&result->processName, "urxvt") ||
|
||||
} else if (ffStrbufEqualS(&result->processName, "urxvt") ||
|
||||
ffStrbufEqualS(&result->processName, "urxvtd") ||
|
||||
ffStrbufEqualS(&result->processName, "rxvt")
|
||||
)
|
||||
ffStrbufEqualS(&result->processName, "rxvt")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "rxvt-unicode");
|
||||
else if(ffStrbufStartsWithS(&result->processName, "ptyxis-agent"))
|
||||
} else if (ffStrbufStartsWithS(&result->processName, "ptyxis-agent")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "Ptyxis");
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
else if(ffStrbufEqualS(&result->processName, "iTerm.app") || ffStrbufStartsWithS(&result->processName, "iTermServer-"))
|
||||
else if (ffStrbufEqualS(&result->processName, "iTerm.app") || ffStrbufStartsWithS(&result->processName, "iTermServer-"))
|
||||
ffStrbufInitStatic(&result->prettyName, "iTerm");
|
||||
else if(ffStrbufEndsWithS(&result->exePath, "Terminal.app/Contents/MacOS/Terminal"))
|
||||
{
|
||||
else if (ffStrbufEndsWithS(&result->exePath, "Terminal.app/Contents/MacOS/Terminal")) {
|
||||
ffStrbufSetStatic(&result->processName, "Apple_Terminal"); // $TERM_PROGRAM, for terminal font detection
|
||||
ffStrbufInitStatic(&result->prettyName, "Apple Terminal");
|
||||
}
|
||||
else if(ffStrbufEqualS(&result->processName, "Apple_Terminal"))
|
||||
} else if (ffStrbufEqualS(&result->processName, "Apple_Terminal")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "Apple Terminal");
|
||||
else if(ffStrbufEndsWithS(&result->exePath, "Warp.app/Contents/MacOS/stable"))
|
||||
{
|
||||
} else if (ffStrbufEndsWithS(&result->exePath, "Warp.app/Contents/MacOS/stable")) {
|
||||
ffStrbufSetStatic(&result->processName, "WarpTerminal"); // $TERM_PROGRAM, for terminal font detection
|
||||
ffStrbufInitStatic(&result->prettyName, "Warp");
|
||||
}
|
||||
else if(ffStrbufEqualS(&result->processName, "WarpTerminal"))
|
||||
} else if (ffStrbufEqualS(&result->processName, "WarpTerminal")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "Warp");
|
||||
}
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
#elif defined(__HAIKU__)
|
||||
|
||||
else if(ffStrbufEqualS(&result->processName, "Terminal"))
|
||||
else if (ffStrbufEqualS(&result->processName, "Terminal"))
|
||||
ffStrbufInitStatic(&result->prettyName, "Haiku Terminal");
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
else if(strncmp(result->exeName, result->processName.chars, result->processName.length) == 0) // if exeName starts with processName, print it. Otherwise print processName
|
||||
else if (strncmp(result->exeName, result->processName.chars, result->processName.length) == 0) { // if exeName starts with processName, print it. Otherwise print processName
|
||||
ffStrbufInitS(&result->prettyName, result->exeName);
|
||||
else
|
||||
} else {
|
||||
ffStrbufInitCopy(&result->prettyName, &result->processName);
|
||||
}
|
||||
|
||||
fftsGetTerminalVersion(&result->processName, result->exePath.length > 0 ? &result->exePath : &result->exe, &result->version);
|
||||
}
|
||||
|
||||
#if defined(MAXPATH)
|
||||
#define FF_EXE_PATH_LEN MAXPATH
|
||||
# define FF_EXE_PATH_LEN MAXPATH
|
||||
#elif defined(PATH_MAX)
|
||||
#define FF_EXE_PATH_LEN PATH_MAX
|
||||
# define FF_EXE_PATH_LEN PATH_MAX
|
||||
#else
|
||||
#define FF_EXE_PATH_LEN 260
|
||||
# define FF_EXE_PATH_LEN 260
|
||||
#endif
|
||||
|
||||
const FFShellResult* ffDetectShell()
|
||||
{
|
||||
const FFShellResult* ffDetectShell() {
|
||||
static FFShellResult result;
|
||||
static bool init = false;
|
||||
if(init)
|
||||
if (init) {
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.processName);
|
||||
@@ -419,8 +401,7 @@ const FFShellResult* ffDetectShell()
|
||||
pid_t ppid = getppid();
|
||||
|
||||
const char* ignoreParent = getenv("FFTS_IGNORE_PARENT");
|
||||
if (ignoreParent && ffStrEquals(ignoreParent, "1"))
|
||||
{
|
||||
if (ignoreParent && ffStrEquals(ignoreParent, "1")) {
|
||||
FF_STRBUF_AUTO_DESTROY _ = ffStrbufCreate();
|
||||
ffProcessGetBasicInfoLinux(ppid, &_, &ppid, NULL);
|
||||
}
|
||||
@@ -432,12 +413,12 @@ const FFShellResult* ffDetectShell()
|
||||
return &result;
|
||||
}
|
||||
|
||||
const FFTerminalResult* ffDetectTerminal()
|
||||
{
|
||||
const FFTerminalResult* ffDetectTerminal() {
|
||||
static FFTerminalResult result;
|
||||
static bool init = false;
|
||||
if(init)
|
||||
if (init) {
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.processName);
|
||||
@@ -451,8 +432,9 @@ const FFTerminalResult* ffDetectTerminal()
|
||||
|
||||
pid_t ppid = (pid_t) ffDetectShell()->ppid;
|
||||
|
||||
if (ppid)
|
||||
if (ppid) {
|
||||
ppid = getTerminalInfo(&result, ppid);
|
||||
}
|
||||
getTerminalFromEnv(&result);
|
||||
setTerminalInfoDetails(&result);
|
||||
|
||||
|
||||
@@ -19,32 +19,22 @@
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
static uint32_t getShellInfo(FFShellResult* result, uint32_t pid)
|
||||
{
|
||||
static uint32_t getShellInfo(FFShellResult* result, uint32_t pid) {
|
||||
uint32_t ppid = 0;
|
||||
bool gui = false;
|
||||
|
||||
while (pid != 0 && ffProcessGetInfoWindows(pid, &ppid, &result->processName, &result->exe, &result->exeName, &result->exePath, &gui))
|
||||
{
|
||||
while (pid != 0 && ffProcessGetInfoWindows(pid, &ppid, &result->processName, &result->exe, &result->exeName, &result->exePath, &gui)) {
|
||||
ffStrbufSet(&result->prettyName, &result->processName);
|
||||
if (ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe"))
|
||||
if (ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe")) {
|
||||
ffStrbufSubstrBefore(&result->prettyName, result->prettyName.length - 4);
|
||||
}
|
||||
|
||||
//Common programs that are between terminal and own process, but are not the shell
|
||||
// Common programs that are between terminal and own process, but are not the shell
|
||||
if (
|
||||
!gui && (
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "sudo") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "su") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "gdb") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "lldb") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "lldb-dap") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "python") || // python on windows generates shim executables
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "fastfetch") || // scoop warps the real binaries with a "shim" exe
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "flashfetch") ||
|
||||
ffStrbufContainIgnCaseS(&result->prettyName, "debug") ||
|
||||
ffStrbufContainIgnCaseS(&result->prettyName, "time") ||
|
||||
ffStrbufStartsWithIgnCaseS(&result->prettyName, "ConEmuC") // https://github.com/fastfetch-cli/fastfetch/issues/488#issuecomment-1619982014
|
||||
)) {
|
||||
!gui && (ffStrbufIgnCaseEqualS(&result->prettyName, "sudo") || ffStrbufIgnCaseEqualS(&result->prettyName, "su") || ffStrbufIgnCaseEqualS(&result->prettyName, "gdb") || ffStrbufIgnCaseEqualS(&result->prettyName, "lldb") || ffStrbufIgnCaseEqualS(&result->prettyName, "lldb-dap") || ffStrbufIgnCaseEqualS(&result->prettyName, "python") || // python on windows generates shim executables
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "fastfetch") || // scoop warps the real binaries with a "shim" exe
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "flashfetch") || ffStrbufContainIgnCaseS(&result->prettyName, "debug") || ffStrbufContainIgnCaseS(&result->prettyName, "time") || ffStrbufStartsWithIgnCaseS(&result->prettyName, "ConEmuC") // https://github.com/fastfetch-cli/fastfetch/issues/488#issuecomment-1619982014
|
||||
)) {
|
||||
ffStrbufClear(&result->processName);
|
||||
ffStrbufClear(&result->prettyName);
|
||||
ffStrbufClear(&result->exe);
|
||||
@@ -55,16 +45,14 @@ static uint32_t getShellInfo(FFShellResult* result, uint32_t pid)
|
||||
|
||||
result->pid = pid;
|
||||
|
||||
if (gui)
|
||||
{
|
||||
if (gui) {
|
||||
// Started without shell
|
||||
// In this case, terminal process will be created by fastfetch itself.
|
||||
ppid = 0;
|
||||
if (ffStrbufIgnCaseEqualS(&result->prettyName, "explorer"))
|
||||
if (ffStrbufIgnCaseEqualS(&result->prettyName, "explorer")) {
|
||||
ffStrbufSetS(&result->prettyName, "Windows Explorer");
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
} else {
|
||||
result->ppid = ppid;
|
||||
}
|
||||
|
||||
@@ -73,101 +61,92 @@ static uint32_t getShellInfo(FFShellResult* result, uint32_t pid)
|
||||
return ppid;
|
||||
}
|
||||
|
||||
static void setShellInfoDetails(FFShellResult* result)
|
||||
{
|
||||
if(ffStrbufIgnCaseEqualS(&result->prettyName, "pwsh"))
|
||||
static void setShellInfoDetails(FFShellResult* result) {
|
||||
if (ffStrbufIgnCaseEqualS(&result->prettyName, "pwsh")) {
|
||||
ffStrbufSetS(&result->prettyName, "PowerShell");
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "powershell"))
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "powershell")) {
|
||||
ffStrbufSetS(&result->prettyName, "Windows PowerShell");
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "powershell_ise"))
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "powershell_ise")) {
|
||||
ffStrbufSetS(&result->prettyName, "Windows PowerShell ISE");
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "cmd"))
|
||||
{
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "cmd")) {
|
||||
ffStrbufSetS(&result->prettyName, "CMD");
|
||||
|
||||
if (instance.config.general.detectVersion)
|
||||
{
|
||||
if (instance.config.general.detectVersion) {
|
||||
FF_AUTO_CLOSE_FD HANDLE snapshot = NULL;
|
||||
while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, result->pid)) && GetLastError() == ERROR_BAD_LENGTH) {}
|
||||
while (!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, result->pid)) && GetLastError() == ERROR_BAD_LENGTH) {}
|
||||
|
||||
if(snapshot)
|
||||
{
|
||||
if (snapshot) {
|
||||
MODULEENTRY32W module;
|
||||
module.dwSize = sizeof(module);
|
||||
for(BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module))
|
||||
{
|
||||
if(wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0)
|
||||
{
|
||||
for (BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module)) {
|
||||
if (wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0) {
|
||||
FF_STRBUF_AUTO_DESTROY clinkVersion = ffStrbufCreate();
|
||||
if (ffGetFileVersion(module.szExePath, NULL, &clinkVersion))
|
||||
if (ffGetFileVersion(module.szExePath, NULL, &clinkVersion)) {
|
||||
ffStrbufAppendF(&result->prettyName, " (with Clink %s)", clinkVersion.chars);
|
||||
else
|
||||
} else {
|
||||
ffStrbufAppendS(&result->prettyName, " (with Clink)");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "nu"))
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "nu")) {
|
||||
ffStrbufSetS(&result->prettyName, "nushell");
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "explorer"))
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "explorer")) {
|
||||
ffStrbufSetS(&result->prettyName, "Windows Explorer");
|
||||
}
|
||||
}
|
||||
|
||||
static bool getTerminalFromEnv(FFTerminalResult* result)
|
||||
{
|
||||
if(
|
||||
static bool getTerminalFromEnv(FFTerminalResult* result) {
|
||||
if (
|
||||
result->processName.length > 0 &&
|
||||
ffStrbufIgnCaseCompS(&result->processName, "explorer") != 0
|
||||
) return false;
|
||||
ffStrbufIgnCaseCompS(&result->processName, "explorer") != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* term = getenv("ConEmuPID");
|
||||
|
||||
if(term)
|
||||
{
|
||||
//ConEmu
|
||||
if (term) {
|
||||
// ConEmu
|
||||
uint32_t pid = (uint32_t) strtoul(term, NULL, 10);
|
||||
result->pid = pid;
|
||||
if(ffProcessGetInfoWindows(pid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL))
|
||||
{
|
||||
if (ffProcessGetInfoWindows(pid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL)) {
|
||||
ffStrbufSet(&result->prettyName, &result->processName);
|
||||
if(ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe"))
|
||||
if (ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe")) {
|
||||
ffStrbufSubstrBefore(&result->prettyName, result->prettyName.length - 4);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
term = "ConEmu";
|
||||
}
|
||||
}
|
||||
|
||||
//SSH
|
||||
if(getenv("SSH_TTY") != NULL)
|
||||
// SSH
|
||||
if (getenv("SSH_TTY") != NULL) {
|
||||
term = getenv("SSH_TTY");
|
||||
}
|
||||
|
||||
//Windows Terminal
|
||||
if(!term && (
|
||||
getenv("WT_SESSION") != NULL ||
|
||||
getenv("WT_PROFILE_ID") != NULL
|
||||
)) term = "WindowsTerminal";
|
||||
// Windows Terminal
|
||||
if (!term && (getenv("WT_SESSION") != NULL || getenv("WT_PROFILE_ID") != NULL)) {
|
||||
term = "WindowsTerminal";
|
||||
}
|
||||
|
||||
//Alacritty
|
||||
if(!term && (
|
||||
getenv("ALACRITTY_SOCKET") != NULL ||
|
||||
getenv("ALACRITTY_LOG") != NULL ||
|
||||
getenv("ALACRITTY_WINDOW_ID") != NULL
|
||||
)) term = "Alacritty";
|
||||
// Alacritty
|
||||
if (!term && (getenv("ALACRITTY_SOCKET") != NULL || getenv("ALACRITTY_LOG") != NULL || getenv("ALACRITTY_WINDOW_ID") != NULL)) {
|
||||
term = "Alacritty";
|
||||
}
|
||||
|
||||
if(!term)
|
||||
if (!term) {
|
||||
term = getenv("TERM_PROGRAM");
|
||||
}
|
||||
|
||||
//Normal Terminal
|
||||
if(!term)
|
||||
// Normal Terminal
|
||||
if (!term) {
|
||||
term = getenv("TERM");
|
||||
}
|
||||
|
||||
if(term)
|
||||
{
|
||||
if (term) {
|
||||
ffStrbufSetS(&result->processName, term);
|
||||
ffStrbufSetS(&result->prettyName, term);
|
||||
ffStrbufSetS(&result->exe, term);
|
||||
@@ -178,33 +157,27 @@ static bool getTerminalFromEnv(FFTerminalResult* result)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool detectDefaultTerminal(FFTerminalResult* result)
|
||||
{
|
||||
static bool detectDefaultTerminal(FFTerminalResult* result) {
|
||||
wchar_t regPath[128] = L"SOFTWARE\\Classes\\PackagedCom\\ClassIndex\\";
|
||||
wchar_t* uuid = regPath + strlen("SOFTWARE\\Classes\\PackagedCom\\ClassIndex\\");
|
||||
DWORD bufSize = 80;
|
||||
if (RegGetValueW(HKEY_CURRENT_USER, L"Console\\%%Startup", L"DelegationTerminal", RRF_RT_REG_SZ, NULL, uuid, &bufSize) == ERROR_SUCCESS)
|
||||
{
|
||||
if(wcscmp(uuid, L"{00000000-0000-0000-0000-000000000000}") == 0 || // Let Windows decide
|
||||
wcscmp(uuid, L"{B23D10C0-E52E-411E-9D5B-C09FDF709C7D}") == 0) // Conhost
|
||||
if (RegGetValueW(HKEY_CURRENT_USER, L"Console\\%%Startup", L"DelegationTerminal", RRF_RT_REG_SZ, NULL, uuid, &bufSize) == ERROR_SUCCESS) {
|
||||
if (wcscmp(uuid, L"{00000000-0000-0000-0000-000000000000}") == 0 || // Let Windows decide
|
||||
wcscmp(uuid, L"{B23D10C0-E52E-411E-9D5B-C09FDF709C7D}") == 0) // Conhost
|
||||
{
|
||||
goto conhost;
|
||||
}
|
||||
|
||||
FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
|
||||
if(ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regPath, &hKey, NULL))
|
||||
{
|
||||
if (ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regPath, &hKey, NULL)) {
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
|
||||
if(ffRegGetSubKey(hKey, 0, &path, NULL))
|
||||
{
|
||||
if (ffStrbufStartsWithS(&path, "Microsoft.WindowsTerminal"))
|
||||
{
|
||||
if (ffRegGetSubKey(hKey, 0, &path, NULL)) {
|
||||
if (ffStrbufStartsWithS(&path, "Microsoft.WindowsTerminal")) {
|
||||
ffStrbufSetS(&result->processName, "WindowsTerminal.exe");
|
||||
ffStrbufSetS(&result->prettyName, "WindowsTerminal");
|
||||
|
||||
PWSTR programFiles = NULL;
|
||||
if (SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, NULL, &programFiles)))
|
||||
{
|
||||
if (SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, NULL, &programFiles))) {
|
||||
ffStrbufSetWS(&result->exe, programFiles);
|
||||
CoTaskMemFree(programFiles);
|
||||
programFiles = NULL;
|
||||
@@ -213,13 +186,10 @@ static bool detectDefaultTerminal(FFTerminalResult* result)
|
||||
ffStrbufAppend(&result->exe, &path);
|
||||
ffStrbufAppendS(&result->exe, "\\WindowsTerminal.exe");
|
||||
|
||||
if(ffPathExists(result->exe.chars, FF_PATHTYPE_FILE))
|
||||
{
|
||||
if (ffPathExists(result->exe.chars, FF_PATHTYPE_FILE)) {
|
||||
result->exeName = result->exe.chars + ffStrbufLastIndexC(&result->exe, '\\') + 1;
|
||||
ffStrbufSet(&result->exePath, &result->exe);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ffStrbufDestroy(&result->exe);
|
||||
ffStrbufInitMove(&result->exe, &path);
|
||||
result->exeName = "";
|
||||
@@ -234,14 +204,13 @@ static bool detectDefaultTerminal(FFTerminalResult* result)
|
||||
conhost:;
|
||||
ULONG_PTR conhostPid = 0;
|
||||
ULONG size;
|
||||
if(NT_SUCCESS(NtQueryInformationProcess(NtCurrentProcess(), ProcessConsoleHostProcess, &conhostPid, sizeof(conhostPid), &size)) && conhostPid != 0)
|
||||
{
|
||||
if (NT_SUCCESS(NtQueryInformationProcess(NtCurrentProcess(), ProcessConsoleHostProcess, &conhostPid, sizeof(conhostPid), &size)) && conhostPid != 0) {
|
||||
// For Windows Terminal, it reports the PID of OpenConsole
|
||||
if(ffProcessGetInfoWindows((uint32_t) conhostPid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL))
|
||||
{
|
||||
if (ffProcessGetInfoWindows((uint32_t) conhostPid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL)) {
|
||||
ffStrbufSet(&result->prettyName, &result->processName);
|
||||
if(ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe"))
|
||||
if (ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe")) {
|
||||
ffStrbufSubstrBefore(&result->prettyName, result->prettyName.length - 4);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -250,10 +219,8 @@ conhost:;
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint32_t getTerminalInfo(FFTerminalResult* result, uint32_t pid)
|
||||
{
|
||||
if (getenv("MSYSTEM"))
|
||||
{
|
||||
static uint32_t getTerminalInfo(FFTerminalResult* result, uint32_t pid) {
|
||||
if (getenv("MSYSTEM")) {
|
||||
// Don't try to detect terminals in MSYS shell
|
||||
// It won't work because MSYS doesn't follow process tree of native Windows programs
|
||||
return 0;
|
||||
@@ -262,11 +229,9 @@ static uint32_t getTerminalInfo(FFTerminalResult* result, uint32_t pid)
|
||||
uint32_t ppid = 0;
|
||||
bool gui;
|
||||
|
||||
while (pid != 0 && ffProcessGetInfoWindows(pid, &ppid, &result->processName, &result->exe, &result->exeName, &result->exePath, &gui))
|
||||
{
|
||||
if (!gui)
|
||||
{
|
||||
//We are in nested shell
|
||||
while (pid != 0 && ffProcessGetInfoWindows(pid, &ppid, &result->processName, &result->exe, &result->exeName, &result->exePath, &gui)) {
|
||||
if (!gui) {
|
||||
// We are in nested shell
|
||||
ffStrbufClear(&result->processName);
|
||||
ffStrbufClear(&result->prettyName);
|
||||
ffStrbufClear(&result->exe);
|
||||
@@ -277,13 +242,13 @@ static uint32_t getTerminalInfo(FFTerminalResult* result, uint32_t pid)
|
||||
}
|
||||
|
||||
ffStrbufSet(&result->prettyName, &result->processName);
|
||||
if(ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe"))
|
||||
if (ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe")) {
|
||||
ffStrbufSubstrBefore(&result->prettyName, result->prettyName.length - 4);
|
||||
}
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(&result->prettyName, "sihost") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "explorer") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "wininit")
|
||||
) {
|
||||
if (ffStrbufIgnCaseEqualS(&result->prettyName, "sihost") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "explorer") ||
|
||||
ffStrbufIgnCaseEqualS(&result->prettyName, "wininit")) {
|
||||
// A CUI program created by Windows Explorer will spawn a conhost as its child.
|
||||
// However the conhost process is just a placeholder;
|
||||
// The true terminal can be Windows Terminal or others.
|
||||
@@ -293,9 +258,7 @@ static uint32_t getTerminalInfo(FFTerminalResult* result, uint32_t pid)
|
||||
ffStrbufClear(&result->exePath);
|
||||
result->exeName = "";
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
result->pid = pid;
|
||||
result->ppid = ppid;
|
||||
}
|
||||
@@ -305,36 +268,33 @@ static uint32_t getTerminalInfo(FFTerminalResult* result, uint32_t pid)
|
||||
return ppid;
|
||||
}
|
||||
|
||||
static void setTerminalInfoDetails(FFTerminalResult* result)
|
||||
{
|
||||
if(ffStrbufIgnCaseEqualS(&result->prettyName, "WindowsTerminal"))
|
||||
ffStrbufSetStatic(&result->prettyName, ffStrbufContainIgnCaseS(&result->exe, ".WindowsTerminalPreview_")
|
||||
? "Windows Terminal Preview"
|
||||
: "Windows Terminal"
|
||||
);
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "conhost"))
|
||||
static void setTerminalInfoDetails(FFTerminalResult* result) {
|
||||
if (ffStrbufIgnCaseEqualS(&result->prettyName, "WindowsTerminal")) {
|
||||
ffStrbufSetStatic(&result->prettyName, ffStrbufContainIgnCaseS(&result->exe, ".WindowsTerminalPreview_") ? "Windows Terminal Preview" : "Windows Terminal");
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "conhost")) {
|
||||
ffStrbufSetStatic(&result->prettyName, "Windows Console");
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "Code"))
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "Code")) {
|
||||
ffStrbufSetStatic(&result->prettyName, "Visual Studio Code");
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "explorer"))
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "explorer")) {
|
||||
ffStrbufSetStatic(&result->prettyName, "Windows Explorer");
|
||||
else if(ffStrbufEqualS(&result->prettyName, "wezterm-gui"))
|
||||
} else if (ffStrbufEqualS(&result->prettyName, "wezterm-gui")) {
|
||||
ffStrbufSetStatic(&result->prettyName, "WezTerm");
|
||||
else if(ffStrbufIgnCaseEqualS(&result->prettyName, "sshd") || ffStrbufStartsWithIgnCaseS(&result->prettyName, "sshd-"))
|
||||
{
|
||||
} else if (ffStrbufIgnCaseEqualS(&result->prettyName, "sshd") || ffStrbufStartsWithIgnCaseS(&result->prettyName, "sshd-")) {
|
||||
const char* tty = getenv("SSH_TTY");
|
||||
if (tty) ffStrbufSetS(&result->prettyName, tty);
|
||||
if (tty) {
|
||||
ffStrbufSetS(&result->prettyName, tty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
|
||||
|
||||
const FFShellResult* ffDetectShell(void)
|
||||
{
|
||||
const FFShellResult* ffDetectShell(void) {
|
||||
static FFShellResult result;
|
||||
static bool init = false;
|
||||
if(init)
|
||||
if (init) {
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.processName);
|
||||
@@ -348,34 +308,37 @@ const FFShellResult* ffDetectShell(void)
|
||||
result.tty = -1;
|
||||
|
||||
uint32_t ppid;
|
||||
if(!ffProcessGetInfoWindows(0, &ppid, NULL, NULL, NULL, NULL, NULL))
|
||||
if (!ffProcessGetInfoWindows(0, &ppid, NULL, NULL, NULL, NULL, NULL)) {
|
||||
return &result;
|
||||
}
|
||||
|
||||
const char* ignoreParent = getenv("FFTS_IGNORE_PARENT");
|
||||
if (ignoreParent && ffStrEquals(ignoreParent, "1"))
|
||||
if (ignoreParent && ffStrEquals(ignoreParent, "1")) {
|
||||
ffProcessGetInfoWindows(ppid, &ppid, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
ppid = getShellInfo(&result, ppid);
|
||||
|
||||
if (result.processName.length > 0)
|
||||
{
|
||||
if (result.processName.length > 0) {
|
||||
setShellInfoDetails(&result);
|
||||
char tmp[MAX_PATH];
|
||||
strcpy(tmp, result.exeName);
|
||||
char* ext = strrchr(tmp, '.');
|
||||
if (ext) *ext = '\0';
|
||||
if (ext) {
|
||||
*ext = '\0';
|
||||
}
|
||||
fftsGetShellVersion(result.exePath.length > 0 ? &result.exePath : &result.exe, tmp, &result.version);
|
||||
}
|
||||
|
||||
return &result;
|
||||
}
|
||||
|
||||
const FFTerminalResult* ffDetectTerminal(void)
|
||||
{
|
||||
const FFTerminalResult* ffDetectTerminal(void) {
|
||||
static FFTerminalResult result;
|
||||
static bool init = false;
|
||||
if(init)
|
||||
if (init) {
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.processName);
|
||||
@@ -389,16 +352,18 @@ const FFTerminalResult* ffDetectTerminal(void)
|
||||
result.ppid = 0;
|
||||
|
||||
uint32_t ppid = ffDetectShell()->ppid;
|
||||
if(ppid)
|
||||
if (ppid) {
|
||||
getTerminalInfo(&result, ppid);
|
||||
}
|
||||
|
||||
if(result.processName.length == 0)
|
||||
if (result.processName.length == 0) {
|
||||
getTerminalFromEnv(&result);
|
||||
if(result.processName.length == 0)
|
||||
}
|
||||
if (result.processName.length == 0) {
|
||||
detectDefaultTerminal(&result);
|
||||
}
|
||||
|
||||
if(result.processName.length > 0)
|
||||
{
|
||||
if (result.processName.length > 0) {
|
||||
setTerminalInfoDetails(&result);
|
||||
fftsGetTerminalVersion(&result.processName, result.exePath.length > 0 ? &result.exePath : &result.exe, &result.version);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user