paleofetch

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 6fd093aa596a3d4b8b43190079a9827981284536
parent d36c6858d0dea2b7860cd82a4dfa7afbbe6b3fc3
Author: sam-barr <samfbarr@outlook.com>
Date:   Wed, 22 Apr 2020 12:43:10 -0500

added terminal and gpu output

Diffstat:
MMakefile | 2+-
MREADME.md | 8++------
Mpaleofetch.c | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -CFLAGS=-O3 -Wall -Wextra -lX11 +CFLAGS=-O3 -Wall -Wextra -lX11 -lpci PREFIX=$(HOME)/.local all: paleofetch diff --git a/README.md b/README.md @@ -1,12 +1,8 @@ paleofetch ========== -Like neofetch, but incomplete, written in ~350 lines of C instead of 10,000 lines of bash, -and runs in like 0.01 seconds. - -This is a WIP, and definitely not a minimum viable product. Currently it only supports Arch Linux with X running. - -If anyone has input for the features I have yet to implement, I would love to hear them. +Like neofetch, but incomplete, written in ~400 lines of C instead of 10,000 lines of bash, +and runs a lot faster. Currently it only supports Arch Linux with X running. Example output: diff --git a/paleofetch.c b/paleofetch.c @@ -6,6 +6,7 @@ #include <sys/utsname.h> #include <sys/sysinfo.h> +#include <pci/pci.h> #include <X11/Xlib.h> @@ -49,11 +50,10 @@ void halt_and_catch_fire(const char *message) { } /* - * Removes the first len characters of substring from str - * Currently assumes that strlen(substring) >= len - * Returns index where substring was found, or -1 if substring isn't found + * Returns index of substring in str, if it is there + * Assumes that strlen(substring) >= len */ -int remove_substring(char *str, const char* substring, size_t len) { +int contains_substring(const char *str, const char*substring, size_t len) { if(len == 0) return -1; /* search for substring */ @@ -72,15 +72,25 @@ int remove_substring(char *str, const char* substring, size_t len) { offset++; } + return offset; +} + +/* + * Removes the first len characters of substring from str + * Assumes that strlen(substring) >= len + * Returns index where substring was found, or -1 if substring isn't found + */ +void remove_substring(char *str, const char* substring, size_t len) { /* shift over the rest of the string to remove substring */ + int offset = contains_substring(str, substring, len); + if(offset < 0) return; + int i = 0; for(;;) { if(*(str+offset+i) == '\0') break; *(str+offset+i) = *(str+offset+i+len); i++; } - - return offset; } char *get_title() { @@ -211,6 +221,12 @@ char *get_resolution() { return resolution; } +char *get_terminal() { + char *terminal = malloc(BUF_SIZE); + strncpy(terminal, getenv("TERM"), BUF_SIZE); + return terminal; +} + char *get_cpu() { FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); /* read from cpu info */ if(cpuinfo == NULL) { @@ -243,6 +259,32 @@ char *get_cpu() { return cpu; } +char *get_gpu() { + // inspired by https://github.com/pciutils/pciutils/edit/master/example.c + char *gpu = malloc(BUF_SIZE); + struct pci_access *pacc; + struct pci_dev *dev; + + pacc = pci_alloc(); + pci_init(pacc); + pci_scan_bus(pacc); + dev = pacc->devices; + + while(dev != NULL) { + pci_fill_info(dev, PCI_FILL_IDENT); + pci_lookup_name(pacc, gpu, BUF_SIZE, PCI_LOOKUP_DEVICE | PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id); + /* as far as I know, this is the only way to check if its a graphics card */ + if(contains_substring(gpu, "Graphics", 8) >= 0) break; + + dev = dev->next; + } + + remove_substring(gpu, "Corporation ", 12); + + pci_cleanup(pacc); + return gpu; +} + char *get_memory() { int total_memory, used_memory; int total, shared, memfree, buffers, cached, reclaimable; @@ -324,12 +366,14 @@ int main() { char *packages = get_packages(); char *shell = get_shell(); char *resolution = get_resolution(); + char *terminal = get_terminal(); char *cpu = get_cpu(); + char *gpu = get_gpu(); char *memory = get_memory(); char *colors1 = get_colors1(); char *colors2 = get_colors2(); - printf(FORMAT_STR, title, bar, os, host, kernel, uptime, packages, shell, resolution, "TERMINAL", cpu, "GPU", memory, colors1, colors2); + printf(FORMAT_STR, title, bar, os, host, kernel, uptime, packages, shell, resolution, terminal, cpu, gpu, memory, colors1, colors2); free(title); free(bar); @@ -340,7 +384,9 @@ int main() { free(packages); free(shell); free(resolution); + free(terminal); free(cpu); + free(gpu); free(memory); free(colors1); free(colors2);