fordon_greeman / sfetch

feat: colored text, first argument -v and new ascii Browse files
theidioticdev committed 2026-09-12 parent 5c01f03 commit d5133e69e560dbd441ea4fc07fb4db0666aa4fae
Showing 2 changed files with 40 additions and 32 deletions. UnifiedSplit
+2 −2 Makefile
@@ -1,8 +1,8 @@
1 1 PREFIX ?= /usr/local
2 2 BINDIR := $(PREFIX)/bin
3 3
4 -CC := clang
5 -CFLAGS := -Wall -Wextra -Werror -std=c11 -pedantic -g -fcolor-diagnostics
4 +CC := gcc
5 +CFLAGS := -Wall -Wextra -Werror -std=c11 -pedantic -g
6 6
7 7 SRC := src/main.c
8 8 OBJ := build/main.o
+38 −30 src/main.c
@@ -3,32 +3,38 @@
3 3 #include <string.h>
4 4 #include <stdlib.h>
5 5
6 +#define C_RESET "\033[0m"
7 +#define C_BOLD "\033[1m"
8 +#define C_BLUE "\033[1;34m"
9 +#define C_YELLOW "\033[1;33m"
10 +#define C_CYAN "\033[1;36m"
11 +#define C_GREEN "\033[1;32m"
12 +#define C_RED "\033[1;31m"
13 +#define C_BLACK "\033[1;30m"
14 +
15 +static char *version = "0.1.3";
16 +
6 17 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 -" ";
18 +" ████████ \n"
19 +" ██████████ \n"
20 +" █████████ \n"
21 +" ███████ \n"
22 +" ██████ ██ ██ ██ ██ ██ ██ ██ \n"
23 +" ███████ \n"
24 +" █████████ \n"
25 +" ██████████ \n"
26 +" ████████ ";
19 27
20 28 void printAscii(void) {
21 - printf("%s\n\n", asciiArt);
29 + printf(C_YELLOW "%s" C_RESET "\n\n", asciiArt);
22 30 }
23 -
24 31 void printOS(void) {
25 32 FILE *fp = fopen("/etc/os-release", "r");
26 33 if (!fp) {
27 - printf("OS: Generic Linux\n");
34 + printf(C_CYAN "OS: " C_RESET "Generic Linux\n");
28 35 return;
29 36 }
30 -
31 - char line[256];
37 + char line[512];
32 38 while (fgets(line, sizeof(line), fp)) {
33 39 if(strncmp(line, "PRETTY_NAME=", 12) == 0) {
34 40 char *name = line + 12;
@@ -36,38 +42,40 @@ void printOS(void) {
36 42 size_t len = strlen(name);
37 43 if (len > 0 && name[len - 1] == '\n') name[--len] = '\0';
38 44 if (len > 0 && name[len - 1] == '"') name[--len] = '\0';
39 -
40 - printf("OS: %s\n", name);
45 + printf(C_CYAN "OS: " C_RESET "%s\n", name);
41 46 fclose(fp);
42 47 return;
43 48 }
44 -
45 49 }
46 50 fclose(fp);
47 - printf("OS: Generic Linux\n");
51 + printf(C_CYAN "OS: " C_RESET "Generic Linux\n");
48 52 }
49 -
50 53 int printStats(void) {
51 -
54 + char *term = getenv("TERM_PROGRAM");
55 + if (!term) {
56 + term = getenv("TERM");
57 + }
52 58 char *wm = getenv("XDG_SESSION_DESKTOP");
53 59 if (!wm) {
54 60 wm = getenv("DESKTOP_SESSION");
55 61 }
56 62 struct utsname info;
57 -
58 63 if (uname(&info) != 0) {
59 64 perror("uname");
60 65 return 1;
61 66 }
62 67 printOS();
63 - printf("Kernel: %s\n", info.release);
64 - printf("Host: %s\n", info.nodename);
65 - printf("WM: %s\n", wm ? wm : "Unknown");
66 -
68 + printf(C_GREEN "Kernel: " C_RESET "%s\n", info.release);
69 + printf(C_BLUE "Host: " C_RESET "%s\n", info.nodename);
70 + printf(C_RED "WM: " C_RESET "%s\n", wm ? wm : "Unknown / TTY");
71 + printf(C_BLACK "Term: " C_RESET "%s\n", term ? term : "couldn't read terminal name");
67 72 return 0;
68 73 }
69 -
70 -int main(void) {
74 +int main(int argc, char **argv) {
75 + if (argc > 1 && strcmp("-v", argv[1]) == 0) {
76 + printf("sfetch v%s\n", version);
77 + return 0;
78 + }
71 79 printAscii();
72 80 printStats();
73 81 return 0;