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