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

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
CC?=cc
all:
cc fetch.c $(CFLAGS) -o kfetch
$(CC) fetch.c $(CFLAGS) -o kfetch

View File

@ -3,7 +3,7 @@
int main(void) {
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;
for (i = 0; i < sizeof(FUNCS) / sizeof(void *); i++) {
@ -12,8 +12,7 @@ int main(void) {
//If art is less than buffer size
else if (i >= Logo.size)
for (size_t j = 0; j < strlen(Logo.art[Logo.size - 1]); j++)
printf(" ");
printf("%s", Logo.art[Logo.size - 1]);
FUNCS[i]();

58
funcs.h
View File

@ -1,8 +1,12 @@
//Base funcs
#ifndef FUNCS_H
#define FUNCS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <pwd.h>
#include <time.h>
#include <sys/utsname.h>
@ -47,7 +51,7 @@ void Init(void) {
Logo = GetArt();
if (uname(&Uts) < 0) {
fprintf(stderr, "WTF, uname dont work\n");
fprintf(stderr, "kfetch: uaname() failed: %s\n", strerror(errno));
exit(1);
}
}
@ -55,58 +59,59 @@ void Init(void) {
void GetShell(void) {
char *shell = getenv("SHELL");
if (shell == NULL) {
printf("%s SHELL \033[0;37mNothing\033[0m", Logo.color);
printf("%sSHELL \033[0;37mNothing\033[0m", Logo.color);
return;
}
char *splt = strrchr(shell, '/');
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) {
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) {
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;
}
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) {
#ifdef CLOCK
struct timespec uptime;
clock_gettime(CLOCK, &uptime);
int UptimeH = 0;
int UptimeM = 0;
int UptimeH = uptime.tv_sec / 3600;
int UptimeM = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
#ifdef CLOCK
struct timespec uptime;
clock_gettime(CLOCK, &uptime);
printf("%s UPTIME \033[0;37m%dh %dm\033[0m", Logo.color, UptimeH, UptimeM);
UptimeH = uptime.tv_sec / 3600;
UptimeM = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
#else
printf("%s UPTIME \033[0;37m0h 0m\033[0m", Logo.color);
#endif
printf("%sUPTIME \033[0;37m%dh %dm\033[0m", Logo.color, UptimeH, UptimeM);
#endif
}
void GetUser(void) {
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) {
if (Logo.pkg_cmd == NULL) {
printf("%s PKGS \033[0;37m0", Logo.color);
printf("%sPKGS \033[0;37m0", Logo.color);
return;
}
FILE *fp = popen(Logo.pkg_cmd, "r");
printf("%s PKGS \033[0;37m", Logo.color);
printf("%sPKGS \033[0;37m", Logo.color);
char ch;
while ((ch = fgetc(fp)) != '\n')
@ -142,13 +147,25 @@ char *GetOs(void) {
}
void PrintColors(void) {
printf(" ");
for (int i = 0; i < 7; i++)
printf("\033[1;3%dm● \033[0;3%dm● \033[0m", i, i);
}
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) {
@ -198,3 +215,4 @@ LOGO GetArt(void) {
return art;
}
#endif

View File

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

View File

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