fix
This commit is contained in:
parent
d63feaa864
commit
69ddc38152
24
config.h
24
config.h
@ -10,21 +10,21 @@ 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},
|
||||
{" ", Blank},
|
||||
{" ", PrintColors}
|
||||
{" os ", PrintOs},
|
||||
{" kr ", GetKernel},
|
||||
{" usr ", GetUser},
|
||||
{" upt ", GetUptime},
|
||||
{" arch ", GetArch},
|
||||
{" shl ", GetShell},
|
||||
{" pkg ", GetPkg},
|
||||
{" mem ", GetMem},
|
||||
{" mod ", GetModel},
|
||||
{" ", Blank},
|
||||
{" ", PrintColors}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
|
@ -35,7 +35,7 @@ char *Alpine[] = {
|
||||
};
|
||||
|
||||
char *Arch[] = {
|
||||
" ",
|
||||
" ",
|
||||
"\033[1;34m /\\ ",
|
||||
"\033[1;34m / \\ ",
|
||||
"\033[1;34m /\\ \\ ",
|
||||
@ -43,7 +43,7 @@ char *Arch[] = {
|
||||
"\033[1;34m / ,, \\ ",
|
||||
"\033[1;34m / | | -\\ ",
|
||||
"\033[1;34m/_-'' ''-_\\ ",
|
||||
" "
|
||||
" "
|
||||
};
|
||||
|
||||
char *Android[] = {
|
||||
|
29
src/fetch.c
29
src/fetch.c
@ -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;
|
||||
fetch->pkg_cmd = pkg_cmd;
|
||||
|
||||
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) {
|
||||
|
24
src/main.c
24
src/main.c
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user