This commit is contained in:
Your Name 2023-12-28 16:21:23 +03:00
parent 7f7ca8c507
commit 22c4e8cdb0
5 changed files with 47 additions and 19 deletions

View File

@ -1,8 +0,0 @@
CFLAGS?=-s -Os -pedantic -Wall -Wextra
CC?=cc
all:
$(CC) src/*.c -Iinclude -I. $(CFLAGS) -okfetch
clean:
rm obj/* bin/*

8
build.sh Executable file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;
}