This commit is contained in:
Your Name 2024-01-03 13:18:43 +03:00
parent d63feaa864
commit 69ddc38152
5 changed files with 41 additions and 42 deletions

View File

@ -10,19 +10,19 @@ typedef struct {
/* Config, EDIT THERE */
#define FONT_COLOR "\033[1;37m"
#define PC_CHAR ""
#define PC_CHAR "<>"
#ifdef _MAIN_H
PARAMETR CONFIG[] = {
{" ", PrintOs},
{" ", GetKernel},
{" ", GetUser},
{" ", GetUptime},
{" ", GetArch},
{" ", GetShell},
{" ", GetPkg},
{" ", GetMem},
{" ", GetModel},
{" os ", PrintOs},
{" kr ", GetKernel},
{" usr ", GetUser},
{" upt ", GetUptime},
{" arch ", GetArch},
{" shl ", GetShell},
{" pkg ", GetPkg},
{" mem ", GetMem},
{" mod ", GetModel},
{" ", Blank},
{" ", PrintColors}
};

View File

@ -33,7 +33,7 @@ typedef struct {
FETCH Init(void);
int GetOs(char *os_name, size_t len);
void GetArt(FETCH *fetch);
void GetArt(FETCH *fetch, int flag);
int GetKernel(const char *title, const FETCH fetch);
int PrintOs(const char *title, const FETCH fetch);
int PrintColors(const char *title, const FETCH fetch);

View File

@ -24,7 +24,7 @@ FETCH Init(void) {
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", fetch.uts.sysname);
fetch.font_color = FONT_COLOR;
GetArt(&fetch);
GetArt(&fetch, 1);
return fetch;
}
@ -53,40 +53,43 @@ int GetOs(char *buf, size_t len) {
return 1;
}
void SetArt(FETCH *fetch, size_t size, char *pkg_cmd, char **logo, char *color) {
void SetArt(FETCH *fetch, size_t size, char *pkg_cmd, char **logo, char *color, int flag) {
fetch->logo_size = size / sizeof(char *);
fetch->logo = logo;
if (flag)
fetch->pkg_cmd = pkg_cmd;
fetch->color = color;
}
void GetArt(FETCH *fetch) {
void GetArt(FETCH *fetch, int flag) {
if (strstr(fetch->os_name, "Debian"))
SetArt(fetch, sizeof(Debian), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Debian, "\033[0;31m");
SetArt(fetch, sizeof(Debian), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Debian, "\033[0;31m", flag);
else if (strstr(fetch->os_name, "Void"))
SetArt(fetch, sizeof(Void), "xbps-query -l | wc -l", Void, "\033[0;32m");
SetArt(fetch, sizeof(Void), "xbps-query -l | wc -l", Void, "\033[0;32m", flag);
else if (strstr(fetch->os_name, "Alpine"))
SetArt(fetch, sizeof(Alpine), "grep 'P:' /lib/apk/db/installed | wc -l", Alpine, "\033[1;34m");
SetArt(fetch, sizeof(Alpine), "grep 'P:' /lib/apk/db/installed | wc -l", Alpine, "\033[1;34m", flag);
else if (strstr(fetch->os_name, "Arch") || strstr(fetch->os_name, "Artix"))
SetArt(fetch, sizeof(Arch), "pacman -Qq | wc -l", Arch, "\033[0;34m");
SetArt(fetch, sizeof(Arch), "pacman -Qq | wc -l", Arch, "\033[0;34m", flag);
else if (strstr(fetch->os_name, "PlainOs"))
SetArt(fetch, sizeof(PlainOs), NULL, PlainOs, "\033[37m");
SetArt(fetch, sizeof(PlainOs), NULL, PlainOs, "\033[37m", flag);
else if (strstr(fetch->os_name, "OpenBSD"))
SetArt(fetch, sizeof(OpenBSD), "/bin/ls -1 /var/db/pkg/ | wc -l | tr -d ' '", OpenBSD, "\033[1;33m");
SetArt(fetch, sizeof(OpenBSD), "/bin/ls -1 /var/db/pkg/ | wc -l | tr -d ' '", OpenBSD, "\033[1;33m", flag);
else if (strstr(fetch->os_name, "Ubuntu"))
SetArt(fetch, sizeof(Ubuntu), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Ubuntu, "\033[1;33m");
SetArt(fetch, sizeof(Ubuntu), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Ubuntu, "\033[1;33m", flag);
else if (!chdir("/system"))
SetArt(fetch, sizeof(Android), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Android, "\033[32m");
SetArt(fetch, sizeof(Android), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Android, "\033[32m", flag);
else
SetArt(fetch, sizeof(Unknow), NULL, Unknow, "\033[1;36m");
SetArt(fetch, sizeof(Unknow), NULL, Unknow, "\033[1;36m", flag);
}
int GetKernel(const char *title, const FETCH fetch) {

View File

@ -1,32 +1,28 @@
#define _MAIN_H
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include "fetch.h"
#include "config.h"
int main(int argc, char **argv) {
unsigned int l_flag = 0;
unsigned int s_flag = 0;
char *d_flag = NULL;
int opt;
while ((opt = getopt(argc, argv, "hlsd:")) != -1) {
while ((opt = getopt(argc, argv, "hld:")) != -1) {
switch (opt) {
case 'l':
l_flag = 1;
break;
case 's':
s_flag = 1;
break;
case 'd':
d_flag = optarg;
break;
case 'h':
default:
printf("kfetch [hl]\n\t[-h Help menu] [-s Strip lines]\n\t[-l Dont print logo]\n\t[-d N Set N as distro name]\n");
printf("kfetch [hl]\n\t[-h Help menu] [-l Dont print logo]\n\t[-d N Set N as distro name]\n");
return 0;
}
}
@ -34,7 +30,7 @@ int main(int argc, char **argv) {
FETCH fetch = Init();
if (d_flag != NULL) {
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", d_flag);
GetArt(&fetch);
GetArt(&fetch, 0);
}
int flag = 0;
@ -49,7 +45,7 @@ int main(int argc, char **argv) {
/* Strip */
char *title = CONFIG[i].title;
if (s_flag) {
if (l_flag) {
size_t len = strlen(title);
for (size_t i = 0; i < len; i++) {
if (title[0] != ' ')
@ -60,14 +56,14 @@ int main(int argc, char **argv) {
}
/* Function exec */
if (!CONFIG[i].func(title, fetch)) {
flag = 0;
printf("\033[0m\n");
if (CONFIG[i].func(title, fetch)) {
flag = 1;
printf("\033[0m");
}
else {
flag = 1;
printf("\033[0m");
flag = 0;
printf("\033[0m\n");
}
}