2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2021-02-19 16:23:41 +01:00
|
|
|
void printTerminalName(FFstate* state, const char* pid)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
|
|
|
|
char file[256];
|
|
|
|
|
sprintf(file, "/proc/%s/stat", pid);
|
|
|
|
|
|
|
|
|
|
FILE* stat = fopen(file, "r");
|
|
|
|
|
if(stat == NULL)
|
|
|
|
|
{
|
2021-02-22 17:14:46 +01:00
|
|
|
char error[300];
|
2021-02-20 19:08:23 +01:00
|
|
|
sprintf(error, "fopen(\"%s\", \"r\") == NULL", file);
|
|
|
|
|
ffPrintError(state, "Terminal", error);
|
2021-02-18 22:25:36 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char name[256];
|
|
|
|
|
char ppid[256];
|
2021-02-18 23:04:31 +01:00
|
|
|
if(fscanf(stat, "%*s (%[^)])%*s%s", name, ppid) != 2)
|
2021-02-19 16:23:41 +01:00
|
|
|
{
|
2021-02-20 19:08:23 +01:00
|
|
|
ffPrintError(state, "Terminal", "fscanf(stat, \"%*s (%[^)])%*s%s\", name, ppid) != 2");
|
2021-02-18 23:04:31 +01:00
|
|
|
return;
|
2021-02-19 16:23:41 +01:00
|
|
|
}
|
2021-02-18 22:25:36 +01:00
|
|
|
|
|
|
|
|
fclose(stat);
|
|
|
|
|
|
|
|
|
|
if (
|
2021-02-27 14:40:03 +01:00
|
|
|
strcmp(name, "bash") == 0 ||
|
|
|
|
|
strcmp(name, "sh") == 0 ||
|
|
|
|
|
strcmp(name, "zsh") == 0 ||
|
|
|
|
|
strcmp(name, "ksh") == 0 ||
|
|
|
|
|
strcmp(name, "fish") == 0 ||
|
|
|
|
|
strcmp(name, "sudo") == 0 ||
|
|
|
|
|
strcmp(name, "su") == 0 ||
|
|
|
|
|
strcmp(name, "doas") == 0 ||
|
|
|
|
|
strcmp(name, "strace") == 0 )
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2021-02-19 16:23:41 +01:00
|
|
|
printTerminalName(state, ppid);
|
|
|
|
|
return;
|
2021-02-18 22:25:36 +01:00
|
|
|
}
|
2021-02-19 16:23:41 +01:00
|
|
|
|
|
|
|
|
ffPrintLogoAndKey(state, "Terminal");
|
|
|
|
|
|
|
|
|
|
if(
|
2021-02-18 22:25:36 +01:00
|
|
|
strcmp(name, "systemd") == 0 ||
|
|
|
|
|
strcmp(name, "init") == 0 ||
|
|
|
|
|
strcmp(ppid, "0") == 0 )
|
|
|
|
|
{
|
|
|
|
|
puts("TTY");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-19 16:23:41 +01:00
|
|
|
puts(name);
|
2021-02-18 22:25:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffPrintTerminal(FFstate* state)
|
|
|
|
|
{
|
|
|
|
|
char ppid[256];
|
|
|
|
|
sprintf(ppid, "%i", getppid());
|
2021-02-19 16:23:41 +01:00
|
|
|
printTerminalName(state, ppid);
|
2021-02-18 22:25:36 +01:00
|
|
|
}
|