TerminalShell: add support for tcsh

which is the default shell for freebsd
This commit is contained in:
李通洲
2022-10-27 16:30:49 +08:00
parent 302a588812
commit 2ee5b3b7a5
2 changed files with 22 additions and 3 deletions
@@ -71,6 +71,17 @@ static void getShellVersionFish(FFstrbuf* exe, FFstrbuf* version)
ffStrbufSubstrAfterLastC(version, ' ');
}
static void getShellVersionTcsh(FFstrbuf* exe, FFstrbuf* version)
{
ffProcessAppendStdOut(version, (char* const[]) {
exe->chars,
"--version",
NULL
}); // tcsh 6.24.01 (Astron) 2022-05-12 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec
ffStrbufSubstrAfterFirstC(version, ' '); // 6.24.01 (Astron) 2022-05-12 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec
ffStrbufSubstrBeforeFirstC(version, ' '); // 6.24.01
}
static void getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version)
{
#ifdef _WIN32
@@ -128,6 +139,8 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version)
getShellVersionFish(exe, version);
else if(strcasecmp(exeName, "pwsh") == 0)
getShellVersionPwsh(exe, version);
else if(strcasecmp(exeName, "csh") == 0 || strcasecmp(exeName, "tcsh") == 0)
getShellVersionTcsh(exe, version);
else if(strcasecmp(exeName, "nu") == 0)
getShellVersionNu(exe, version);
@@ -153,6 +153,8 @@ static void getTerminalShell(FFTerminalShellResult* result, pid_t pid)
strcasecmp(name, "sh") == 0 ||
strcasecmp(name, "zsh") == 0 ||
strcasecmp(name, "ksh") == 0 ||
strcasecmp(name, "csh") == 0 ||
strcasecmp(name, "tcsh") == 0 ||
strcasecmp(name, "fish") == 0 ||
strcasecmp(name, "dash") == 0 ||
strcasecmp(name, "pwsh") == 0 ||
@@ -251,11 +253,15 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
}
}
static void getUserShellFromEnv(FFTerminalShellResult* result)
static void getUserShellFromEnv(const FFinstance* instance, FFTerminalShellResult* result)
{
ffStrbufAppendS(&result->userShellExe, getenv("SHELL"));
if(instance->state.passwd->pw_shell[0] != '\0')
ffStrbufAppendS(&result->userShellExe, instance->state.passwd->pw_shell);
else
ffStrbufAppendS(&result->userShellExe, getenv("SHELL"));
if(result->userShellExe.length == 0)
return;
setExeName(&result->userShellExe, &result->userShellExeName);
//If shell detection via processes failed
@@ -337,7 +343,7 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
getTerminalShell(&result, getppid());
getTerminalFromEnv(&result);
getUserShellFromEnv(&result);
getUserShellFromEnv(instance, &result);
getShellVersion(&result.shellExe, result.shellExeName, &result.shellVersion);
if(strcasecmp(result.shellExeName, result.userShellExeName) != 0)