Загрузить файлы в «/»

This commit is contained in:
8nlight 2023-10-18 23:55:28 +03:00
parent c40de0102a
commit d9bce24e52
5 changed files with 45 additions and 27 deletions

View File

@ -1,3 +1,4 @@
CFLAGS?= -s -flto -Os -pedantic CFLAGS?= -s -flto -Os -pedantic
CC?=cc
all: all:
cc fetch.c $(CFLAGS) -o kfetch $(CC) fetch.c $(CFLAGS) -o kfetch

View File

@ -3,7 +3,7 @@
int main(void) { int main(void) {
Init(); Init();
void (*FUNCS[])(void) = {PrintOs, GetKernel, GetShell, GetUptime, GetUser, GetPkgs, GetArch, Blank, PrintColors}; void (*FUNCS[])(void) = {PrintOs, GetAvg, GetKernel, GetShell, GetUptime, GetUser, GetPkgs, GetArch, Blank, PrintColors};
size_t i; size_t i;
for (i = 0; i < sizeof(FUNCS) / sizeof(void *); i++) { for (i = 0; i < sizeof(FUNCS) / sizeof(void *); i++) {
@ -12,8 +12,7 @@ int main(void) {
//If art is less than buffer size //If art is less than buffer size
else if (i >= Logo.size) else if (i >= Logo.size)
for (size_t j = 0; j < strlen(Logo.art[Logo.size - 1]); j++) printf("%s", Logo.art[Logo.size - 1]);
printf(" ");
FUNCS[i](); FUNCS[i]();

54
funcs.h
View File

@ -1,8 +1,12 @@
//Base funcs //Base funcs
#ifndef FUNCS_H
#define FUNCS_H
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <pwd.h> #include <pwd.h>
#include <time.h> #include <time.h>
#include <sys/utsname.h> #include <sys/utsname.h>
@ -47,7 +51,7 @@ void Init(void) {
Logo = GetArt(); Logo = GetArt();
if (uname(&Uts) < 0) { if (uname(&Uts) < 0) {
fprintf(stderr, "WTF, uname dont work\n"); fprintf(stderr, "kfetch: uaname() failed: %s\n", strerror(errno));
exit(1); exit(1);
} }
} }
@ -55,58 +59,59 @@ void Init(void) {
void GetShell(void) { void GetShell(void) {
char *shell = getenv("SHELL"); char *shell = getenv("SHELL");
if (shell == NULL) { if (shell == NULL) {
printf("%s SHELL \033[0;37mNothing\033[0m", Logo.color); printf("%sSHELL \033[0;37mNothing\033[0m", Logo.color);
return; return;
} }
char *splt = strrchr(shell, '/'); char *splt = strrchr(shell, '/');
if (splt != NULL) if (splt != NULL)
printf("%s SHELL \033[0;37m%s\033[0m", Logo.color, splt + 1); printf("%sSHELL \033[0;37m%s\033[0m", Logo.color, splt + 1);
} }
void GetKernel(void) { void GetKernel(void) {
printf("%s KERNEL \033[0;37m%s\033[0m", Logo.color, Uts.release); printf("%sKERNEL \033[0;37m%s\033[0m", Logo.color, Uts.release);
} }
void PrintOs(void) { void PrintOs(void) {
if (Os == NULL) { if (Os == NULL) {
printf("%s OS \033[0;37m%s\033[0m", Logo.color, Uts.sysname); printf("%sOS \033[0;37m%s\033[0m", Logo.color, Uts.sysname);
return; return;
} }
printf("%s OS \033[0;37m%s\033[0m", Logo.color, Os + strlen("PRETTY_NAME= ")); printf("%sOS \033[0;37m%s\033[0m", Logo.color, Os + strlen("PRETTY_NAME= "));
} }
void GetUptime(void) { void GetUptime(void) {
#ifdef CLOCK int UptimeH = 0;
int UptimeM = 0;
#ifdef CLOCK
struct timespec uptime; struct timespec uptime;
clock_gettime(CLOCK, &uptime); clock_gettime(CLOCK, &uptime);
int UptimeH = uptime.tv_sec / 3600; UptimeH = uptime.tv_sec / 3600;
int UptimeM = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60); UptimeM = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
printf("%s UPTIME \033[0;37m%dh %dm\033[0m", Logo.color, UptimeH, UptimeM); #endif
#else printf("%sUPTIME \033[0;37m%dh %dm\033[0m", Logo.color, UptimeH, UptimeM);
printf("%s UPTIME \033[0;37m0h 0m\033[0m", Logo.color);
#endif
} }
void GetUser(void) { void GetUser(void) {
struct passwd *pw = getpwuid(geteuid()); struct passwd *pw = getpwuid(geteuid());
printf("%s USER \033[0;37m%s\033[0m", Logo.color, pw->pw_name); printf("%sUSER \033[0;37m%s\033[0m", Logo.color, pw->pw_name);
} }
void GetPkgs(void) { void GetPkgs(void) {
if (Logo.pkg_cmd == NULL) { if (Logo.pkg_cmd == NULL) {
printf("%s PKGS \033[0;37m0", Logo.color); printf("%sPKGS \033[0;37m0", Logo.color);
return; return;
} }
FILE *fp = popen(Logo.pkg_cmd, "r"); FILE *fp = popen(Logo.pkg_cmd, "r");
printf("%s PKGS \033[0;37m", Logo.color); printf("%sPKGS \033[0;37m", Logo.color);
char ch; char ch;
while ((ch = fgetc(fp)) != '\n') while ((ch = fgetc(fp)) != '\n')
@ -142,13 +147,25 @@ char *GetOs(void) {
} }
void PrintColors(void) { void PrintColors(void) {
printf(" ");
for (int i = 0; i < 7; i++) for (int i = 0; i < 7; i++)
printf("\033[1;3%dm● \033[0;3%dm● \033[0m", i, i); printf("\033[1;3%dm● \033[0;3%dm● \033[0m", i, i);
} }
void GetArch(void) { void GetArch(void) {
printf("%s ARCH \033[0;37m%s", Logo.color, Uts.machine); printf("%sARCH \033[0;37m%s", Logo.color, Uts.machine);
}
void GetAvg(void) {
double avg[3] = {0, 0, 0};
#ifndef __ANDROID__
if (getloadavg(avg, sizeof(avg) / sizeof(avg[0])) < 0) {
fprintf(stderr, "kfetch: getloadavg() failed\n");
return;
}
#endif
printf("%sLoadAvg \033[0;37m%.2f %.2f %.2f", Logo.color, avg[0], avg[1], avg[2]);
} }
void Blank(void) { void Blank(void) {
@ -198,3 +215,4 @@ LOGO GetArt(void) {
return art; return art;
} }
#endif

View File

@ -1,6 +1,7 @@
Edit FUNCS in fetch.c Edit FUNCS in fetch.c
GetShell GetShell
GetAvg
GetKernel GetKernel
PrintOs PrintOs
GetUptime GetUptime

View File

@ -19,7 +19,7 @@ char *Void[] = {
}; };
char *Alpine[] = { char *Alpine[] = {
" /\\ /\\ ", "\033[34m /\\ /\\ ",
"\033[34m / \\ \\ ", "\033[34m / \\ \\ ",
"\033[34m / \\ \\ ", "\033[34m / \\ \\ ",
"\033[34m / \\ \\ ", "\033[34m / \\ \\ ",
@ -40,7 +40,6 @@ char *Arch[] = {
}; };
char *Unknow[] = { char *Unknow[] = {
" ",
"\033[1;36m ___ ", "\033[1;36m ___ ",
"\033[1;36m (\033[0m..\033[1;36m | ", "\033[1;36m (\033[0m..\033[1;36m | ",
"\033[1;36m (\033[33m<> \033[1;36m| ", "\033[1;36m (\033[33m<> \033[1;36m| ",