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

View File

@ -33,7 +33,7 @@ typedef struct {
FETCH Init(void); FETCH Init(void);
int GetOs(char *os_name, size_t len); 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 GetKernel(const char *title, const FETCH fetch);
int PrintOs(const char *title, const FETCH fetch); int PrintOs(const char *title, const FETCH fetch);
int PrintColors(const char *title, const FETCH fetch); int PrintColors(const char *title, const FETCH fetch);

View File

@ -35,7 +35,7 @@ char *Alpine[] = {
}; };
char *Arch[] = { char *Arch[] = {
" ", " ",
"\033[1;34m /\\ ", "\033[1;34m /\\ ",
"\033[1;34m / \\ ", "\033[1;34m / \\ ",
"\033[1;34m /\\ \\ ", "\033[1;34m /\\ \\ ",
@ -43,7 +43,7 @@ char *Arch[] = {
"\033[1;34m / ,, \\ ", "\033[1;34m / ,, \\ ",
"\033[1;34m / | | -\\ ", "\033[1;34m / | | -\\ ",
"\033[1;34m/_-'' ''-_\\ ", "\033[1;34m/_-'' ''-_\\ ",
" " " "
}; };
char *Android[] = { char *Android[] = {

View File

@ -24,7 +24,7 @@ FETCH Init(void) {
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", fetch.uts.sysname); snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", fetch.uts.sysname);
fetch.font_color = FONT_COLOR; fetch.font_color = FONT_COLOR;
GetArt(&fetch); GetArt(&fetch, 1);
return fetch; return fetch;
} }
@ -53,40 +53,43 @@ int GetOs(char *buf, size_t len) {
return 1; 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_size = size / sizeof(char *);
fetch->logo = logo; fetch->logo = logo;
fetch->pkg_cmd = pkg_cmd;
if (flag)
fetch->pkg_cmd = pkg_cmd;
fetch->color = color; fetch->color = color;
} }
void GetArt(FETCH *fetch) { void GetArt(FETCH *fetch, int flag) {
if (strstr(fetch->os_name, "Debian")) 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")) 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")) 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")) 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")) 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")) 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")) 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")) 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 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) { int GetKernel(const char *title, const FETCH fetch) {

View File

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