fordon_greeman / sfetch

feat: toggle ascii Browse files
theidioticdev committed 2026-09-18 parent e79d78d commit d872459ff31337c89d7a1bcf22ecf57ba87c29f2
Showing 3 changed files with 60 additions and 20 deletions. UnifiedSplit
+2 −3 .gitignore
@@ -1,5 +1,4 @@
1 -.o
2 bin 1 bin
3 -build 2 +result
4 -.direnv
5 3
4 +lock
+19 −0 src/func.h new file mode 100644
@@ -0,0 +1,19 @@
1 +#ifndef FUNC_H
2 +#define FUNC_H
3 +
4 +#define _POSIX_C_SOURCE 200809L
5 +#define C_RESET "\033[0m"
6 +#define C_BOLD "\033[1m"
7 +#define C_BLUE "\033[1;34m"
8 +#define C_YELLOW "\033[1;33m"
9 +#define C_CYAN "\033[1;36m"
10 +#define C_GREEN "\033[1;32m"
11 +#define C_RED "\033[1;31m"
12 +#define C_PURPLE "\033[1;35m"
13 +
14 +
15 +void printOS(void);
16 +void printAscii(void);
17 +int printStats(void);
18 +
19 +#endif
+39 −17 src/main.c
@@ -1,6 +1,7 @@
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <sys/utsname.h> 2 #include <sys/utsname.h>
3 #include <string.h> 3 #include <string.h>
4 +#include <unistd.h>
4 #include <stdlib.h> 5 #include <stdlib.h>
5 6
6 #define C_RESET "\033[0m" 7 #define C_RESET "\033[0m"
@@ -12,23 +13,27 @@
12 #define C_RED "\033[1;31m" 13 #define C_RED "\033[1;31m"
13 #define C_PURPLE "\033[1;35m" 14 #define C_PURPLE "\033[1;35m"
14 15
15 -static char *version = "0.1.3"; 16 +#define ENABLE_ASCII 1
16 17
17 -static const char asciiArt[] = 18 +const char *version = "0.1.5";
18 -" ████████ \n"
19 -" ██████████ \n"
20 -" █████████ \n"
21 -" ███████ \n"
22 -" ██████ ██ ██ ██ ██ ██ ██ ██ \n"
23 -" ███████ \n"
24 -" █████████ \n"
25 -" ██████████ \n"
26 -" ████████ ";
27 19
28 void printAscii(void) { 20 void printAscii(void) {
21 +#if ENABLE_ASCII
22 + static const char asciiArt[] =
23 + " ████████ \n"
24 + " ██████████ \n"
25 + " █████████ \n"
26 + " ███████ \n"
27 + " ██████ ██ ██ ██ ██ ██ ██ ██ \n"
28 + " ███████ \n"
29 + " █████████ \n"
30 + " ██████████ \n"
31 + " ████████ ";
29 printf(C_YELLOW "%s" C_RESET "\n\n", asciiArt); 32 printf(C_YELLOW "%s" C_RESET "\n\n", asciiArt);
33 +#endif
30 } 34 }
31 void printOS(void) { 35 void printOS(void) {
36 +#ifdef __linux__
32 FILE *fp = fopen("/etc/os-release", "r"); 37 FILE *fp = fopen("/etc/os-release", "r");
33 if (!fp) { 38 if (!fp) {
34 printf(C_CYAN "OS: " C_RESET "Generic Linux\n"); 39 printf(C_CYAN "OS: " C_RESET "Generic Linux\n");
@@ -49,6 +54,14 @@ void printOS(void) {
49 } 54 }
50 fclose(fp); 55 fclose(fp);
51 printf(C_CYAN "OS: " C_RESET "Generic Linux\n"); 56 printf(C_CYAN "OS: " C_RESET "Generic Linux\n");
57 +#else
58 + struct utsname otherOS;
59 + if (uname(&otherOS) != 0) {
60 + perror("uname");
61 + return;
62 + }
63 + printf(C_CYAN "OS: " C_RESET "%s\n", otherOS.sysname);
64 +#endif
52 } 65 }
53 int printStats(void) { 66 int printStats(void) {
54 char *term = getenv("TERM_PROGRAM"); 67 char *term = getenv("TERM_PROGRAM");
@@ -59,22 +72,31 @@ int printStats(void) {
59 if (!wm) { 72 if (!wm) {
60 wm = getenv("DESKTOP_SESSION"); 73 wm = getenv("DESKTOP_SESSION");
61 } 74 }
75 + char *session = getenv("XDG_SESSION_TYPE");
62 struct utsname info; 76 struct utsname info;
63 if (uname(&info) != 0) { 77 if (uname(&info) != 0) {
64 perror("uname"); 78 perror("uname");
65 return 1; 79 return 1;
66 } 80 }
67 printOS(); 81 printOS();
68 - printf(C_GREEN "Kernel: " C_RESET "%s\n", info.release); 82 + printf(C_GREEN "Kernel: " C_RESET "%s %s\n",info.sysname, info.release);
69 printf(C_BLUE "Host: " C_RESET "%s\n", info.nodename); 83 printf(C_BLUE "Host: " C_RESET "%s\n", info.nodename);
70 - printf(C_RED "WM: " C_RESET "%s\n", wm ? wm : "Unknown / TTY"); 84 + printf(C_RED "WM: " C_RESET "%s (%s)\n", wm ? wm : "unknown / tty", session ? session : "unknown");
71 - printf(C_PURPLE "Term: " C_RESET "%s\n", term ? term : "couldn't read terminal name"); 85 + printf(C_PURPLE "Term: " C_RESET "%s\n", term ? term : "unknown");
72 return 0; 86 return 0;
73 } 87 }
74 int main(int argc, char **argv) { 88 int main(int argc, char **argv) {
75 - if (argc > 1 && strcmp("-v", argv[1]) == 0) { 89 + for (int i = 1; i < argc; i++) {
76 - printf("sfetch-%s\n", version); 90 + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
77 - return 0; 91 + printf("usage: %s [-v/-h]\n", argv[0]);
92 + return 0;
93 + }
94 + if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
95 + printf("sfetch-%s\n", version);
96 + return 0;
97 + }
98 + fprintf(stderr, "Unknown argument: %s\nUsage: %s [-v/-h]\n", argv[i], argv[0]);
99 + return 1;
78 } 100 }
79 printAscii(); 101 printAscii();
80 printStats(); 102 printStats();