diff --git a/Makefile b/Makefile deleted file mode 100644 index adc568a..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -CFLAGS?=-s -Os -pedantic -Wall -Wextra -CC?=cc - -all: - $(CC) src/*.c -Iinclude -I. $(CFLAGS) -okfetch - -clean: - rm obj/* bin/* diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..2dd208f --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#!/bin/sh +CC=cc +FLAGS="-Os -s" + +$CC -Iinclude -I. src/main.c -c -o main.o +$CC -Iinclude -I. src/fetch.c -c -o fetch.o +$CC $FLAGS main.o fetch.o -o kfetch +rm main.o fetch.o diff --git a/config.h b/config.h index 25cc04a..5e5ec7e 100644 --- a/config.h +++ b/config.h @@ -14,17 +14,17 @@ typedef struct { #ifdef _MAIN_H PARAMETR CONFIG[] = { - {" --- ", GetUser}, - {"\033[31m  ", PrintOs}, - {"\033[32m  ", GetKernel}, - {"\033[33m  ", GetUser}, - {"\033[34m  ", GetUptime}, - {"\033[35m  ", GetArch}, - {"\033[36m  ", GetShell}, - {"\033[37m  ", GetPkg}, - {"\033[38m  ", GetMem}, - {" ", Blank}, - {" ", PrintColors} + {"  ", PrintOs}, + {"  ", GetKernel}, + {"  ", GetUser}, + {"  ", GetUptime}, + {"  ", GetArch}, + {"  ", GetShell}, + {"  ", GetPkg}, + {"  ", GetMem}, + {"  ", GetModel}, + {" ", Blank}, + {" ", PrintColors} }; #endif diff --git a/include/fetch.h b/include/fetch.h index 7feb02a..3d8c741 100644 --- a/include/fetch.h +++ b/include/fetch.h @@ -13,6 +13,13 @@ #endif #define OS_SIZE 128 +#define MODEL_BUFF_SIZE 512 +static const char *MODELS[] = { + "/sys/devices/virtual/dmi/id/product_name", + "/sys/devices/virtual/dmi/id/product_version", + "/sys/firmware/devicetree/base/model" +}; + typedef struct { char os_name[OS_SIZE + 1]; struct utsname uts; @@ -37,5 +44,6 @@ int GetArch(const char *title, const FETCH fetch); int GetShell(const char *title, const FETCH fetch); int GetPkg(const char *title, const FETCH fetch); int GetMem(const char *title, const FETCH fetch); +int GetModel(const char *title, const FETCH fetch); #endif diff --git a/src/fetch.c b/src/fetch.c index 7dbf7f3..e2b4953 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -201,3 +201,23 @@ int GetMem(const char *title, const FETCH fetch) { return 0; } + +int GetModel(const char *title, const FETCH fetch) { + FILE *fp = NULL; + for (size_t i = 0; i < sizeof(MODELS) / sizeof(char *); i++) { + fp = fopen(MODELS[i], "r"); + if (fp != NULL) + break; + } + + if (fp == NULL) + return 1; + + char model_buffer[MODEL_BUFF_SIZE + 1]; + char *ptr = fgets(model_buffer, sizeof(model_buffer), fp); + if (ptr != NULL) + printf("%s%s%s%s", fetch.color, title, fetch.font_color, model_buffer); + + fclose(fp); + return 0; +}