fordon_greeman / sfetch

Branch: 5c01f03
Switch branches/tags
main
theidioticdev feat: get os pretty name 8023aee 2026-09-06
74 lines · 1.7 KB Raw Blame History
1 #include <stdio.h>
2 #include <sys/utsname.h>
3 #include <string.h>
4 #include <stdlib.h>
5
6 static const char asciiArt[] =
7 " \n"
8 " ██████ \n"
9 " ██████████ \n"
10 " ███ ███ \n"
11 " ███ \n"
12 " ████████ \n"
13 " █████████ \n"
14 " ███ \n"
15 " ███ ███ \n"
16 " ██████████ \n"
17 " ██████ \n"
18 " ";
19
20 void printAscii(void) {
21 printf("%s\n\n", asciiArt);
22 }
23
24 void printOS(void) {
25 FILE *fp = fopen("/etc/os-release", "r");
26 if (!fp) {
27 printf("OS: Generic Linux\n");
28 return;
29 }
30
31 char line[256];
32 while (fgets(line, sizeof(line), fp)) {
33 if(strncmp(line, "PRETTY_NAME=", 12) == 0) {
34 char *name = line + 12;
35 if (*name == '"') name++;
36 size_t len = strlen(name);
37 if (len > 0 && name[len - 1] == '\n') name[--len] = '\0';
38 if (len > 0 && name[len - 1] == '"') name[--len] = '\0';
39
40 printf("OS: %s\n", name);
41 fclose(fp);
42 return;
43 }
44
45 }
46 fclose(fp);
47 printf("OS: Generic Linux\n");
48 }
49
50 int printStats(void) {
51
52 char *wm = getenv("XDG_SESSION_DESKTOP");
53 if (!wm) {
54 wm = getenv("DESKTOP_SESSION");
55 }
56 struct utsname info;
57
58 if (uname(&info) != 0) {
59 perror("uname");
60 return 1;
61 }
62 printOS();
63 printf("Kernel: %s\n", info.release);
64 printf("Host: %s\n", info.nodename);
65 printf("WM: %s\n", wm ? wm : "Unknown");
66
67 return 0;
68 }
69
70 int main(void) {
71 printAscii();
72 printStats();
73 return 0;
74 }