forked from nakidai/mycfetch
Refactor
parent
6228e7c143
commit
5267766b10
10
Makefile
10
Makefile
|
@ -1,11 +1,15 @@
|
||||||
CC := gcc
|
CC := cc
|
||||||
CFLAGS :=
|
CFLAGS :=
|
||||||
|
|
||||||
mycfetch: main.c info.c order.c
|
all: mycfetch
|
||||||
$(CC) main.c info.c -o mycfetch $(CFLAGS)
|
|
||||||
|
mycfetch: main.c config.h
|
||||||
|
$(CC) main.c -o mycfetch $(CFLAGS)
|
||||||
|
|
||||||
install: mycfetch
|
install: mycfetch
|
||||||
cp mycfetch /usr/bin/mycfetch
|
cp mycfetch /usr/bin/mycfetch
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm mycfetch
|
rm mycfetch
|
||||||
|
|
||||||
|
.PHONY: all install clean
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
const int max_username_length = 128;
|
||||||
|
const int max_hostname_length = 128;
|
||||||
|
const int max_uptime_length = 40;
|
||||||
|
|
||||||
|
char *art[] = {
|
||||||
|
// FreeBSD
|
||||||
|
"\033[31m_ _\033[0m",
|
||||||
|
"\033[31m\\‾‾‾‾/\033[0m",
|
||||||
|
"\033[31m|^ww^|\033[0m",
|
||||||
|
"\033[31m\\____/\033[0m"
|
||||||
|
|
||||||
|
// Gentoo
|
||||||
|
// "\x1B[38;5;135m /‾\\",
|
||||||
|
// "\x1B[38;5;135m( \x1B[38;5;183mo \x1B[38;5;135m\\",
|
||||||
|
// "\x1B[38;5;135m/ /",
|
||||||
|
// "\x1B[38;5;135m\\__/"
|
||||||
|
|
||||||
|
// Arch
|
||||||
|
// " /\\ ",
|
||||||
|
// " /\\ \\ ",
|
||||||
|
// " / \\ ",
|
||||||
|
// "/__/\\__\\"
|
||||||
|
|
||||||
|
// Just cute cat
|
||||||
|
// " ╱|、 ",
|
||||||
|
// "(˚ˎ。7 ",
|
||||||
|
// " |、˜〵 ",
|
||||||
|
// "じしˍ,)ノ"
|
||||||
|
};
|
48
info.c
48
info.c
|
@ -1,48 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
char *GetKernelVer(void)
|
|
||||||
{
|
|
||||||
FILE *ptr;
|
|
||||||
char *uptime = malloc(50 * sizeof(char));
|
|
||||||
for (int i = 0; i < 50; ++i)
|
|
||||||
uptime[i] = 0;
|
|
||||||
ptr = popen("/bin/uname -r", "r");
|
|
||||||
if (ptr == NULL)
|
|
||||||
return "idk";
|
|
||||||
fgets(uptime, 49, ptr);
|
|
||||||
pclose(ptr);
|
|
||||||
int i = 0;
|
|
||||||
for (i = 0; uptime[i] != 0; ++i);
|
|
||||||
uptime[i-1] = 0;
|
|
||||||
return uptime;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *GetCurrentUser(void)
|
|
||||||
{
|
|
||||||
char *user = getenv("USER");
|
|
||||||
char *host = malloc(25 * sizeof(char));
|
|
||||||
char *out = malloc(50 * sizeof(char));
|
|
||||||
gethostname(host, 25);
|
|
||||||
sprintf(out, "%s@%s", user, host);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *GetUptime(void)
|
|
||||||
{
|
|
||||||
FILE *ptr;
|
|
||||||
char *uptime = malloc(50 * sizeof(char));
|
|
||||||
for (int i = 0; i < 50; ++i)
|
|
||||||
uptime[i] = 0;
|
|
||||||
ptr = popen("uptime -p", "r");
|
|
||||||
if (ptr == NULL)
|
|
||||||
return "idk";
|
|
||||||
fgets(uptime, 49, ptr);
|
|
||||||
pclose(ptr);
|
|
||||||
int i = 0;
|
|
||||||
for (i = 0; uptime[i] != 0; ++i);
|
|
||||||
uptime[i-1] = 0;
|
|
||||||
return uptime+3;
|
|
||||||
}
|
|
3
info.h
3
info.h
|
@ -1,3 +0,0 @@
|
||||||
char *GetKernelVer(void); // takes kernel version from /proc/version
|
|
||||||
char *GetCurrentUser(void); // user@pc
|
|
||||||
char *GetUptime(void); // takes uptime from uptime -p
|
|
43
main.c
43
main.c
|
@ -1,11 +1,46 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <sys/utsname.h>
|
||||||
#include <string.h>
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "info.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
void getuptime(char *buffer, int max_length)
|
||||||
|
{
|
||||||
|
struct timespec uptime;
|
||||||
|
clock_gettime(CLOCK_BOOTTIME, &uptime);
|
||||||
|
int days = uptime.tv_sec / 86400;
|
||||||
|
int hours = uptime.tv_sec / 3600 % 24;
|
||||||
|
int minutes = uptime.tv_sec / 60 % 60;
|
||||||
|
int seconds = uptime.tv_sec % 60;
|
||||||
|
|
||||||
|
if (uptime.tv_sec < 60)
|
||||||
|
snprintf(buffer, max_length, "Up %d seconds", seconds);
|
||||||
|
else if (uptime.tv_sec < 3600)
|
||||||
|
snprintf(buffer, max_length, "Up %d minutes", minutes);
|
||||||
|
else if (uptime.tv_sec < 86400)
|
||||||
|
snprintf(buffer, max_length, "Up %d hours, %d minutes", hours, minutes);
|
||||||
|
else
|
||||||
|
snprintf(buffer, max_length, "Up %d days, %d hours, %d minutes", days, hours, minutes);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
#include "order.c"
|
struct utsname uname_buf;
|
||||||
|
struct timespec uptime_buf;
|
||||||
|
char hostname[max_hostname_length];
|
||||||
|
char username[max_username_length];
|
||||||
|
char uptime[max_uptime_length];
|
||||||
|
|
||||||
|
gethostname(hostname, max_hostname_length);
|
||||||
|
getlogin_r(username, max_username_length);
|
||||||
|
getuptime(uptime, max_uptime_length);
|
||||||
|
|
||||||
|
uname(&uname_buf);
|
||||||
|
printf("%s %s@%s\n", art[0], username, hostname);
|
||||||
|
printf("%s --\n", art[1]);
|
||||||
|
printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release);
|
||||||
|
printf("%s %s\n", art[3], uptime);
|
||||||
|
// #include "order.c"
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
37
order.c
37
order.c
|
@ -1,37 +0,0 @@
|
||||||
/*
|
|
||||||
* Printf needed info
|
|
||||||
* Don't include here any libraries
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Gentoo
|
|
||||||
|
|
||||||
// printf("\x1B[38;5;135m /‾\\ \x1B[38;5;255m%s\n", GetCurrentUser());
|
|
||||||
// printf("\x1B[38;5;135m( \x1B[38;5;183mo \x1B[38;5;135m\\\n");
|
|
||||||
// printf("\x1B[38;5;135m/ / \x1B[38;5;255m%s\n", GetKernelVer());
|
|
||||||
// printf("\x1B[38;5;135m\\__/ \x1B[38;5;255m%s\n", GetUptime());
|
|
||||||
|
|
||||||
printf(" /‾\\ %s\n", GetCurrentUser());
|
|
||||||
printf("( o \\\n");
|
|
||||||
printf("/ / %s\n", GetKernelVer());
|
|
||||||
printf("\\__/ %s\n", GetUptime());
|
|
||||||
|
|
||||||
// Arch
|
|
||||||
|
|
||||||
// printf(" /\\ %s\n", GetCurrentUser());
|
|
||||||
// printf(" /\\ \\\n");
|
|
||||||
// printf(" / \\ %s\n", GetKernelVer());
|
|
||||||
// printf("/__/\\__\\ %s\n", GetUptime());
|
|
||||||
|
|
||||||
// FreeBSD
|
|
||||||
|
|
||||||
// printf("\033[31m_ _\033[0m %s\n", GetCurrentUser());
|
|
||||||
// printf("\033[31m\\‾‾‾‾/\033[0m\n");
|
|
||||||
// printf("\033[31m|^ww^|\033[0m %s\n", GetKernelVer());
|
|
||||||
// printf("\033[31m\\____/\033[0m %s\n", GetUptime());
|
|
||||||
|
|
||||||
// Just cat
|
|
||||||
|
|
||||||
// printf(" ╱|、 %s\n", GetCurrentUser());
|
|
||||||
// printf("(˚ˎ。7 \n");
|
|
||||||
// printf(" |、˜〵 %s\n", GetKernelVer());
|
|
||||||
// printf("じしˍ,)ノ %s\n", GetUptime());
|
|
Loading…
Reference in New Issue