summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorauric <104602845+ihateamongus@users.noreply.github.com>2025-09-07 19:23:44 -0500
committerauric <104602845+ihateamongus@users.noreply.github.com>2025-09-07 19:23:44 -0500
commitac363b0b326afc73b7e01d0bed8848ed336e0a39 (patch)
treea67d3835a257f16000581271f243c23632c1c6e0 /tools
parentb59b8b8e5d16af7f0daccb280a4991e3fe428e41 (diff)
refactor: share accent color shm header
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile16
-rw-r--r--tools/exofetch.c181
2 files changed, 197 insertions, 0 deletions
diff --git a/tools/Makefile b/tools/Makefile
new file mode 100644
index 0000000..ae33902
--- /dev/null
+++ b/tools/Makefile
@@ -0,0 +1,16 @@
+CC = cc
+CFLAGS = -std=c99 -Wall -Wextra -pedantic -Os
+LDFLAGS =
+PREFIX ?= /usr/local
+
+all: exofetch
+
+exofetch: exofetch.c
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+
+clean:
+ rm -f exofetch
+
+install: exofetch
+ mkdir -p $(DESTDIR)$(PREFIX)/bin
+ cp -f exofetch $(DESTDIR)$(PREFIX)/bin
diff --git a/tools/exofetch.c b/tools/exofetch.c
new file mode 100644
index 0000000..8111274
--- /dev/null
+++ b/tools/exofetch.c
@@ -0,0 +1,181 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+#include <sys/sysinfo.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <locale.h>
+
+#include "../accent.h"
+
+static ColorShm *accentshm;
+static char accentcol[8] = "#005577";
+
+static void
+updateaccent(void)
+{
+ if (!readaccent(&accentshm, accentcol))
+ memcpy(accentcol, "#005577", 8);
+}
+
+static void
+hex2rgb(const char *hex, int *r, int *g, int *b)
+{
+ unsigned int ri, gi, bi;
+ if (sscanf(hex + 1, "%02x%02x%02x", &ri, &gi, &bi) != 3) {
+ *r = 0x00; *g = 0x55; *b = 0x77;
+ return;
+ }
+ *r = ri; *g = gi; *b = bi;
+}
+
+static const char *icon[] = {
+" ██████████████ ██████████████ ",
+" ██████████████ ██████████████ ",
+" ██████▓▓▓█████ █████▓▓▓██████ ",
+" █████▓▓▓▓█████ █████▓▓▓▓█████ ",
+" █████▓▓▓▓█████ █████▓▓▓▓█████ ",
+" █████▓▓▓▓▓████ ████▓▓▓▓▓█████ ",
+" █████▓▓▓▓▓████████ █████████████████████ ████████▓▓▓▓▓█████ ",
+" ██████▓▓▓▓▓▓▓█████ █████████████████████ █████▓▓▓▓▓▓▓██████ ",
+"▓▓▓▓▓▓▓▓ ██████▓▓▓▓▓▓▓█████ █████████████████████ █████▓▓▓▓▓▓▓██████ ▓▓▓▓▓▓▓▓",
+"▓▓▓▓▓▓▓▓▓ █████▓▓▓▓▓████ ████▓▒▒▒▒▓▓▓▒▒▒▒▓████ ████▓▓▓▓▓█████ ▓▓▓▓▓▓▓▓▓",
+"▓▓▓▓▓▓▓▓▓ █████▓▓▓▓▓████ ████▓▒▒▒▒▓▓▓▒▒▒▒▓████ ████▓▓▓▓▓█████ ▓▓▓▓▓▓▓▓▓",
+"▓▓▓▓▒░░░▒▓▓▓▓ █████▓▓▓▓▓▓▓▓█████▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓█████▓▓▓▓▓▓▓▓█████ ▓▓▓▓▒░░░▒▓▓▓▓",
+"▓▓▓▓▒░░░▒▓▓▓▓ █████▓▓▓▓▓▓▓▓█████▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓█████▓▓▓▓▓▓▓▓█████ ▓▓▓▓▒░░░░▓▓▓▓",
+"▓▓▓▓▒▒▒▒░░░░▒▓▓▓▓ █████████▓▓▓▓▓▒▒▒▓███▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓███▓▒▒▒▒▓▓▓▓█████████ ▓▓▓▓▒░░░░▒▒▒▒▓▓▓▓",
+" ▒▒▒▒▒░░░░▒▓▓▓▓ ██████████▓▓▓▒▒▒▒▓███▓▓▓▓▓███████████▓▓▓▓▓███▓▒▒▒▒▓▓▓▓█████████ ▓▓▓▓▒░░░░▒▒▒▒▒ ",
+" ▓▓▓▓▓░░░░▒▒▒▒▓▓▓▓████████████▓▒▒▒▓███████▓▓▓▓█████▓▓▓▓███████▓▒▒▒▒▓████████████▓▓▓▒▒▒▒░░░░▒▓▓▓▓ ",
+" ████▓▒░░░░░░▒▒▓▓▓████████████▓▒▒▒▓████████▓▓▓▓▓▓▓▓▓▓▓████████▓▒▒▒▓████████████▓▓▓▓▒░░░░░░░▓████ ",
+" ████▓▒▒▒▒░░░░▒▓▓▓▓███████████▓▒▒▒▓▓▓▓████▓▒▒▒▒▒▒▒▒▒▒▒▓████▓▓▓▓▒▒▒▓████████████▓▓▓▒▒░░░▒▒▒▒▓████ ",
+" ▓▓▓▓▓▒░░░▒▒▒▒▓▓▓▓▓███████▓▒▒▒▒▒▒▒▓███▒░░░░░░░░░░░▒▓██▓▒▒▒▒▒▒▒▒▓██████▓▓▓▓▓▒▒▒▒░░░▒▓▓▓▓▓ ",
+" ▓▓▓▓▓▒░░░▒▒▒▒▒▓▓▓▓███████▓▒▒▒▒▒▒▒▓███▒░░░░░░░░░░░▒▓██▓▒▒▒▒▒▒▒▓▓██████▓▓▓▓▓▒▒▒▒░░░▒▓▓▓▓▓ ",
+" ▓▓▓▓▓▒░░░▒▒▒▒▒▒▒▒▓▓▓▓████▓▓▓▒▒░░░▒███▒░░░░░░░░░░░▒▓██▓░░░▒▒▓▓▓████▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▓▓▓▓▓ ",
+" ▓▓▓▓▓▒░░░▒▒▒▒▒▒▒▒▓▓▓▓████▓▓▓▒▒░░░▒███▒░░░░░░░░░░░▒▓██▓░░░▒▒▓▓▓████▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▓▓▓▓▓ ",
+" ▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓██████▓▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░▒▓██████▓▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓ ",
+" ▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓██████▓▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░▒▓██████▓▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓ ",
+" ████▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓████ ",
+" ████▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓████ ",
+" █████▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓█████ ",
+" █████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████████████ ",
+" █████▓▓▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓▓▓█████ ",
+" ████▓▓▒▒▒▓███████████▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░░░░░░░░▒▒▓▓▓▓▓▓▓███████████▓▒▒▒▒▓████ ",
+" ████▓▓▓▓▒▒▒▒▓▓▓▓████████▓▓▓▓▓▓▓▓▒▒▒▒▒░░░░░░░░░░░░▒▒▒▒▓▓▓▓▓▓▓▓█████████▓▓▓▒▒▒▒▓▓▓▓████ ",
+" █████▓▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓████████████▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓████████████▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓█████ ",
+" █████▓▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓████████████▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓████████████▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓█████ ",
+" █████▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓███████████████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓█████ ",
+" █████▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓███████████████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓█████ ",
+" █████▓▓▓▓▓▓▓▓▓▓▓▓█████████████████████▓▓▓██████▓▓█████████████████████▓▓▓▓▓▓▓▓▓▓▓▓█████ ",
+" ██████▓▓▓▓▓▓▓▓████████▓▓▓█████████████▓▓▓█████▓▓▓█████████████▓▓▓████████▓▓▓▓▓▓▓▓▓█████ ",
+" █████████▓▓▓▓▓████████▓▓▓▓████████████▓▓▓█████▓▓▓▓████████████▓▓▓████████▓▓▓▓▓█████████ ",
+" █████▓▓▓▓▓████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████████▓▓▓▓▓█████ ",
+" ██████▓▓▓▓▓▓▓████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████████▓▓▓▓▓▓▓▓█████ ",
+" ██████▓▓▓▓▓▓▓▓████████▓▓▓█████████▓▓▓▓▓▓▓▓▓▓▓█████████▓▓▓████████▓▓▓▓▓▓▓▓██████ ",
+" ██████▓▓▓▓▓▓▓▓████████████████████▓▓▓▓▓▓▓▓▓▓▓████████████████████▓▓▓▓▓▓▓▓██████ ",
+" ██████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓██████████████████████████████████ ",
+" ██████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓██████████████████████████████████ ",
+" ██████▓▓▓▓▓▓██████▓▓▓████▓▓▓▓▓████▓▓▓██████▓▓▓▓▓▓▓█████ ",
+" ██████▓▓▓▓▓▓▓█████▓▓▓████▓▓▓▓▓████▓▓▓██████▓▓▓▓▓▓▓█████ ",
+" █████▓▓▓▓▓▓▓▓█████████████████████████████▓▓▓▓▓▓▓▓█████ ",
+" █████▓▓▓▓▓▓▓▓█████████▓▓▓█████▓▓▓█████████▓▓▓▓▓▓▓▓█████ ",
+" ██████▓▓▓▓▓▓▓█████████▓▓▓▓███▓▓▓▓██████████▓▓▓▓▓▓██████ ",
+" ██████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██████████████████ ",
+" █████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓█████████████████████ ",
+" █████████████████▓▓▓▓▓▓▓▓▓▓▓██████████████████ ",
+" ██████████████████████████████████████████████ ",
+" █████████████ ",
+" █████████████ ",
+NULL};
+
+int
+main(void)
+{
+ setlocale(LC_ALL, "");
+ updateaccent();
+ int r, g, b;
+ hex2rgb(accentcol, &r, &g, &b);
+
+ for (int i = 0; icon[i]; i++)
+ printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m\n", r, g, b, icon[i]);
+
+ printf("\n");
+
+ char host[256] = "";
+ gethostname(host, sizeof host);
+ struct utsname uts;
+ uname(&uts);
+ struct sysinfo info;
+ sysinfo(&info);
+
+ char os[128] = "Unknown";
+ FILE *fp = fopen("/etc/os-release", "r");
+ if (fp) {
+ char line[256];
+ while (fgets(line, sizeof line, fp)) {
+ if (strncmp(line, "PRETTY_NAME=", 12) == 0) {
+ char *p = line + 12;
+ if (*p == '"') p++;
+ char *e = strchr(p, '"');
+ if (e) *e = '\0';
+ snprintf(os, sizeof os, "%s", p);
+ break;
+ }
+ }
+ fclose(fp);
+ }
+
+ long updays = info.uptime / 86400;
+ long uphours = (info.uptime / 3600) % 24;
+ long upmins = (info.uptime / 60) % 60;
+
+ char cpu[128] = "Unknown";
+ fp = fopen("/proc/cpuinfo", "r");
+ if (fp) {
+ char line[256];
+ while (fgets(line, sizeof line, fp)) {
+ if (strncmp(line, "model name", 10) == 0) {
+ char *p = strchr(line, ':');
+ if (p) {
+ p += 2;
+ p[strcspn(p, "\n")] = '\0';
+ snprintf(cpu, sizeof cpu, "%s", p);
+ }
+ break;
+ }
+ }
+ fclose(fp);
+ }
+
+ long totalmem = info.totalram / 1024 / 1024;
+ long freemem = info.freeram / 1024 / 1024;
+ long usedmem = totalmem - freemem;
+
+ char shell[64];
+ snprintf(shell, sizeof shell, "%s", getenv("SHELL") ? getenv("SHELL") : "Unknown");
+ char term[64];
+ snprintf(term, sizeof term, "%s", getenv("TERM") ? getenv("TERM") : "Unknown");
+
+ char packages[32] = "Unknown";
+ if ((fp = popen("dpkg-query -f '${binary:Package}\\n' -W 2>/dev/null | wc -l", "r"))) {
+ if (fgets(packages, sizeof packages, fp))
+ packages[strcspn(packages, "\n")] = '\0';
+ pclose(fp);
+ }
+
+ printf("\x1b[38;2;%d;%d;%dmHost:\x1b[0m %s\n", r, g, b, host);
+ printf("\x1b[38;2;%d;%d;%dmOS:\x1b[0m %s\n", r, g, b, os);
+ printf("\x1b[38;2;%d;%d;%dmKernel:\x1b[0m %s\n", r, g, b, uts.release);
+ printf("\x1b[38;2;%d;%d;%dmUptime:\x1b[0m %ldd %ldh %ldm\n", r, g, b, updays, uphours, upmins);
+ printf("\x1b[38;2;%d;%d;%dmPackages:\x1b[0m %s\n", r, g, b, packages);
+ printf("\x1b[38;2;%d;%d;%dmShell:\x1b[0m %s\n", r, g, b, shell);
+ printf("\x1b[38;2;%d;%d;%dmTerminal:\x1b[0m %s\n", r, g, b, term);
+ printf("\x1b[38;2;%d;%d;%dmCPU:\x1b[0m %s\n", r, g, b, cpu);
+ printf("\x1b[38;2;%d;%d;%dmMemory:\x1b[0m %ldMiB / %ldMiB\n", r, g, b, usedmem, totalmem);
+
+ return 0;
+}