fetchy/fetchy.c

79 lines
1.5 KiB
C

#include <stdio.h>
int day, hour, min, sec, pacman;
char os[50], kernel[50], shell[25];
void getDistro() {
FILE *distroName = popen("cat /etc/*-release | grep 'PRETTY_NAME=' | cut -d '\"' -f2", "r");
fscanf(distroName, "%[^\n]%s", &os);
fclose(distroName);
}
void getKernel() {
FILE *pathKernel = popen("uname -r", "r");
fscanf(pathKernel, "%[^\n]%s", &kernel);
fclose(pathKernel);
}
void getUptime() {
FILE *pathUptime = fopen("/proc/uptime", "r");
fscanf(pathUptime, "%d", &sec);
fclose(pathUptime);
day = (sec/60/60/24);
hour = (sec/60/60%24);
min = (sec/60%60);
}
void getPackages() {
FILE *pacpackages = popen("pacman -Q | wc -l", "r");
fscanf(pacpackages, "%d", &pacman);
fclose(pacpackages);
}
void getShell() {
FILE *shellpath = popen("echo $SHELL", "r");
fscanf(shellpath, "%s", &shell);
fclose(shellpath);
}
void init() {
getDistro();
getKernel();
getUptime();
getPackages();
getShell();
}
int main() {
init();
printf("\n");
printf("\x1b[1m . \x1b\n");
printf("\x1b[1m / \\ \x1b\n");
printf("\x1b[1m / \\ \x1b[36mOS\x1b[0m: %s\n", os);
printf("\x1b[1m /^. \\ \x1b[36mKERNEL\x1b[0m: %s\n", kernel);
printf("\x1b[1m / .-. \\ \x1b[36mUPTIME\x1b[0m: %dd, %dh, %dm\n", day, hour, min);
printf("\x1b[1m / ( ) _\\ \x1b[36mPACKAGES\x1b[0m: %d (pacman)\n", pacman);
printf("\x1b[1m / _.~ ~._^\\ \x1b[36mSHELL\x1b[0m: %s\n", shell);
printf("\x1b[1m /.^ ^.\\ \x1b\n");
printf("\n");
return 0;
}