From c2c0fb397a150ec1ed46124189ba780abc24c5e4 Mon Sep 17 00:00:00 2001 From: sech1p Date: Thu, 15 Apr 2021 10:36:56 +0200 Subject: [PATCH 1/3] Add IntelliJ(-based) IDE's to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e708858..be2e87b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ uwufetch *.zip +*.idea *.vscode *.gz *.1 From 0218e64e0218edcaf008ed1ed81d59bcf09cbfaf Mon Sep 17 00:00:00 2001 From: sech1p Date: Thu, 15 Apr 2021 22:59:43 +0200 Subject: [PATCH 2/3] Add macOS support --- README.md | 2 +- uwufetch.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 103 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 40a5cc2..f3d95ca 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Nyalpine, Nyarch Linuwu, Nyartix Linuwu, Debinyan, Fedowa, GentOwO, GnUwU gUwUix #### Partial support (Either no Ascii art, or no image is provided) -endeavOwO, KDE NeOwOn, nixOwOs, Swackwawe, sOwOlus; Plus FweeBSD, and OwOpenBSD +endeavOwO, KDE NeOwOn, nixOwOs, Swackwawe, sOwOlus; Plus FweeBSD, OwOpenBSD and macOwOS ## Building and installation diff --git a/uwufetch.c b/uwufetch.c index 52ed008..e4fa89e 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -19,7 +19,12 @@ #include #include #include -#include +#ifdef __APPLE__ + #include + #include +#else + #include +#endif #include #include @@ -36,6 +41,22 @@ #define WHITE "\x1b[37m" #define PINK "\x1b[38;5;201m" #define LPINK "\x1b[38;5;213m" +#ifdef __APPLE__ + // buffers where data fetched from sysctl are stored + // CPU + #define CPUBUFFERLEN 128 + + char cpu_buffer[CPUBUFFERLEN]; + size_t cpu_buffer_len = CPUBUFFERLEN; + + // Installed RAM + int64_t mem_buffer = 0; + size_t mem_buffer_len = sizeof(mem_buffer); + + // uptime + struct timeval time_buffer; + size_t time_buffer_len = sizeof(time_buffer); +#endif struct package_manager { @@ -43,7 +64,9 @@ struct package_manager char pkgman_name[16]; // name of the package manager }; struct utsname sys_var; -struct sysinfo sys; +#ifndef __APPLE__ + struct sysinfo sys; +#endif struct winsize win; int ram_total, ram_used = 0; // initialise the variables to store data, gpu array can hold up to 8 gpus @@ -179,12 +202,14 @@ int pkgman() struct package_manager pkgmans[] = { {"apt list --installed 2> /dev/null | wc -l", "(apt)"}, {"apk info 2> /dev/null | wc -l", "(apk)"}, + {"brew list --formulae 2> /dev/null | wc -l", "(brew)"}, {"dnf list installed 2> /dev/null | wc -l", "(dnf)"}, {"qlist -I 2> /dev/null | wc -l", "(emerge)"}, {"flatpak list 2> /dev/null | wc -l", "(flatpack)"}, {"guix package --list-installed 2> /dev/null | wc -l", "(guix)"}, {"nix-store -q --requisites /run/current-sys_vartem/sw 2> /dev/null | wc -l", "(nix)"}, {"pacman -Qq 2> /dev/null | wc -l", "(pacman)"}, + {"port installed 2> /dev/null | tail -n +2 | wc -l", "(port)"}, {"rpm -qa --last 2> /dev/null | wc -l", "(rpm)"}, {"xbps-query -l 2> /dev/null | wc -l", "(xbps)"}, {"zypper se --installed-only 2> /dev/null | wc -l", "(zypper)"}}; @@ -209,6 +234,19 @@ int pkgman() return total; } +#ifdef __APPLE__ +int uptime_mac() +{ + int mib[2] = { CTL_KERN, KERN_BOOTTIME }; + sysctl(mib, 2, &time_buffer, &time_buffer_len, NULL, 0); + + time_t bsec = time_buffer.tv_sec; + time_t csec = time(NULL); + + return difftime(csec, bsec); +} +#endif + void print_info() { // store sys info in the sys again @@ -246,8 +284,13 @@ void print_info() printf("\033[18C%s%sPKGS %s%s%d %s\n", NORMAL, BOLD, NORMAL, NORMAL, pkgs, pkgman_name); if (show_uptime) - printf("\033[18C%s%sUWUPTIME %s" /*"%lid, "*/ "%lih, %lim\n", + #ifndef __APPLE__ + printf("\033[18C%s%sUWUPTIME %s" /*"%lid, "*/ "%lih, %lim\n", NORMAL, BOLD, NORMAL, /*sys.uptime/60/60/24,*/ sys.uptime / 60 / 60, sys.uptime / 60 % 60); + #else + printf("\033[18C%s%sUWUPTIME %s" "%ih, %im\n", + NORMAL, BOLD, NORMAL, (uptime_mac() / 3600), ((uptime_mac() - (3600 * (uptime_mac() / 3600))) / 60)); + #endif if (show_colors) printf("\033[18C%s%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\n", BOLD, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, NORMAL); @@ -276,9 +319,10 @@ void get_info() fclose(os_release); } else - { // try for android vars, or unknown system + { // try for android vars, next for macOS var, or unknown system DIR *system_app = opendir("/system/app/"); DIR *system_priv_app = opendir("/system/priv-app/"); + DIR *library = opendir("/Library/"); if (system_app && system_priv_app) { // android closedir(system_app); @@ -293,6 +337,14 @@ void get_info() if (sscanf(line, "Hardware : %[^\n]", cpu_model)) break; } + else if (library) // macOS + { + closedir(library); + sysctlbyname("machdep.cpu.brand_string", &cpu_buffer, &cpu_buffer_len, NULL, 0); + + sprintf(version_name, "macos"); + sprintf(cpu_model, "%s", cpu_buffer); + } else sprintf(version_name, "unknown"); } @@ -314,6 +366,7 @@ void get_info() truncate_name(kernel); // ram +#ifndef __APPLE__ FILE *meminfo; meminfo = popen("LANG=EN_us free 2> /dev/null", "r"); @@ -333,6 +386,31 @@ void get_info() } } fclose(meminfo); +#else + // Used + FILE *mem_wired_fp, *mem_active_fp, *mem_compressed_fp; + mem_wired_fp = popen("vm_stat | awk '/wired/ { printf $4 }' | cut -d '.' -f 1", "r"); + mem_active_fp = popen("vm_stat | awk '/active/ { printf $3 }' | cut -d '.' -f 1", "r"); + mem_compressed_fp = popen("vm_stat | awk '/occupied/ { printf $5 }' | cut -d '.' -f 1", "r"); + char mem_wired_ch[2137], mem_active_ch[2137], mem_compressed_ch[2137]; + while(fgets(mem_wired_ch, sizeof(mem_wired_ch), mem_wired_fp) != NULL) { + while(fgets(mem_active_ch, sizeof(mem_active_ch), mem_active_fp) != NULL) { + while(fgets(mem_compressed_ch, sizeof(mem_compressed_ch), mem_compressed_fp) != NULL) {} + } + } + + pclose(mem_wired_fp); pclose(mem_active_fp); pclose(mem_compressed_fp); + + int mem_wired = atoi(mem_wired_ch); + int mem_active = atoi(mem_active_ch); + int mem_compressed = atoi(mem_compressed_ch); + + // Total + sysctlbyname("hw.memsize", &mem_buffer, &mem_buffer_len, NULL, 0); + + ram_used = ((mem_wired + mem_active + mem_compressed) * 4 / 1024); + ram_total = mem_buffer / 1024 / 1024; +#endif /* ---------- gpu ---------- */ int gpun = 0; // number of the gpu that the program is searching for to put in the array @@ -349,7 +427,13 @@ void get_info() { // get gpus with lspci command if (strcmp(version_name, "android") != 0) - gpu = popen("lspci -mm 2> /dev/null | grep \"VGA\" | cut --fields=4,6 -d '\"' --output-delimiter=\" \" | sed \"s/ Controller.*//\"", "r"); + { + #ifndef __APPLE__ + gpu = popen("lspci -mm 2> /dev/null | grep \"VGA\" | cut --fields=4,6 -d '\"' --output-delimiter=\" \" | sed \"s/ Controller.*//\"", "r"); + #else + gpu = popen("system_profiler SPDisplaysDataType | awk -F ': ' '/Chipset Model: /{ print $2 }'", "r"); + #endif + } else gpu = popen("getprop ro.hardware.vulkan 2> /dev/null", "r"); } @@ -585,6 +669,17 @@ void print_ascii() YELLOW, RED, YELLOW, WHITE, YELLOW, LPINK, WHITE, LPINK, YELLOW); } + else if (strcmp(version_name, "macos") == 0) + { + printf("\033[1E\033[3C%s .:`\n" + " .--``--.\n" + "%s ww OwO w\n" + "%s w w\n" + "%s w w\n" + "%s w w\n" + " www_-_www\n\n", GREEN, YELLOW, RED, PINK, BLUE); + } + // everything else else printf("\033[0E\033[2C%s._.--._.\n" @@ -674,6 +769,8 @@ void uwu_name() else STRING_TO_UWU("freebsd", "FweeBSD"); else STRING_TO_UWU("openbsd", "OwOpenBSD"); + else STRING_TO_UWU("macos", "macOwOS"); + else { sprintf(version_name, "%s", "unknown"); From 4b2f69c166acfb81f0291d7d3ea0efbd78014442 Mon Sep 17 00:00:00 2001 From: TheDarkBug Date: Fri, 16 Apr 2021 10:48:39 +0200 Subject: [PATCH 3/3] Fixed build errors on linux (line 356) --- uwufetch.c | 123 ++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 57 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index c508b4e..1e43162 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -20,10 +20,10 @@ #include #include #ifdef __APPLE__ - #include - #include +#include +#include #else - #include +#include #endif #include #include @@ -42,20 +42,20 @@ #define PINK "\x1b[38;5;201m" #define LPINK "\x1b[38;5;213m" #ifdef __APPLE__ - // buffers where data fetched from sysctl are stored - // CPU - #define CPUBUFFERLEN 128 +// buffers where data fetched from sysctl are stored +// CPU +#define CPUBUFFERLEN 128 - char cpu_buffer[CPUBUFFERLEN]; - size_t cpu_buffer_len = CPUBUFFERLEN; +char cpu_buffer[CPUBUFFERLEN]; +size_t cpu_buffer_len = CPUBUFFERLEN; - // Installed RAM - int64_t mem_buffer = 0; - size_t mem_buffer_len = sizeof(mem_buffer); +// Installed RAM +int64_t mem_buffer = 0; +size_t mem_buffer_len = sizeof(mem_buffer); - // uptime - struct timeval time_buffer; - size_t time_buffer_len = sizeof(time_buffer); +// uptime +struct timeval time_buffer; +size_t time_buffer_len = sizeof(time_buffer); #endif struct package_manager @@ -65,7 +65,7 @@ struct package_manager }; struct utsname sys_var; #ifndef __APPLE__ - struct sysinfo sys; +struct sysinfo sys; #endif struct winsize win; int ram_total, ram_used = 0; @@ -207,14 +207,14 @@ int pkgman() struct package_manager pkgmans[] = { {"apt list --installed 2> /dev/null | wc -l", "(apt)"}, {"apk info 2> /dev/null | wc -l", "(apk)"}, - {"brew list --formulae 2> /dev/null | wc -l", "(brew)"}, + {"brew list --formulae 2> /dev/null | wc -l", "(brew)"}, {"dnf list installed 2> /dev/null | wc -l", "(dnf)"}, {"qlist -I 2> /dev/null | wc -l", "(emerge)"}, {"flatpak list 2> /dev/null | wc -l", "(flatpack)"}, {"guix package --list-installed 2> /dev/null | wc -l", "(guix)"}, {"nix-store -q --requisites /run/current-sys_vartem/sw 2> /dev/null | wc -l", "(nix)"}, {"pacman -Qq 2> /dev/null | wc -l", "(pacman)"}, - {"port installed 2> /dev/null | tail -n +2 | wc -l", "(port)"}, + {"port installed 2> /dev/null | tail -n +2 | wc -l", "(port)"}, {"rpm -qa --last 2> /dev/null | wc -l", "(rpm)"}, {"xbps-query -l 2> /dev/null | wc -l", "(xbps)"}, {"zypper se --installed-only 2> /dev/null | wc -l", "(zypper)"}}; @@ -242,13 +242,13 @@ int pkgman() #ifdef __APPLE__ int uptime_mac() { - int mib[2] = { CTL_KERN, KERN_BOOTTIME }; - sysctl(mib, 2, &time_buffer, &time_buffer_len, NULL, 0); + int mib[2] = {CTL_KERN, KERN_BOOTTIME}; + sysctl(mib, 2, &time_buffer, &time_buffer_len, NULL, 0); - time_t bsec = time_buffer.tv_sec; - time_t csec = time(NULL); + time_t bsec = time_buffer.tv_sec; + time_t csec = time(NULL); - return difftime(csec, bsec); + return difftime(csec, bsec); } #endif @@ -284,7 +284,7 @@ void print_info() NORMAL, BOLD, NORMAL, (ram_used), ram_total); if (show_resolution) printf("\033[18C%s%sRESOLUTION%s %dx%d\n", - NORMAL, BOLD, NORMAL, screen_width, screen_height); + NORMAL, BOLD, NORMAL, screen_width, screen_height); if (show_shell) printf("\033[18C%s%sSHELL %s%s\n", NORMAL, BOLD, NORMAL, shell); @@ -292,17 +292,17 @@ void print_info() printf("\033[18C%s%sPKGS %s%s%d %s\n", NORMAL, BOLD, NORMAL, NORMAL, pkgs, pkgman_name); if (show_uptime) - #ifndef __APPLE__ - printf("\033[18C%s%sUWUPTIME %s" /*"%lid, "*/ "%lih, %lim\n", +#ifndef __APPLE__ + printf("\033[18C%s%sUWUPTIME %s" /*"%lid, "*/ "%lih, %lim\n", NORMAL, BOLD, NORMAL, /*sys.uptime/60/60/24,*/ sys.uptime / 60 / 60, sys.uptime / 60 % 60); - #else - if(sys.uptime/3600 < 24) +#else + if (sys.uptime / 3600 < 24) printf("\033[18C%s%sUWUPTIME %s%lih, %lim\n", - NORMAL, BOLD, NORMAL, sys.uptime/3600, sys.uptime/60%60); + NORMAL, BOLD, NORMAL, sys.uptime / 3600, sys.uptime / 60 % 60); else printf("\033[18C%s%sUWUPTIME %s%lid, %lih, %lim\n", - NORMAL, BOLD, NORMAL, sys.uptime/86400, sys.uptime/3600%24, sys.uptime/60%60); - #endif + NORMAL, BOLD, NORMAL, sys.uptime / 86400, sys.uptime / 3600 % 24, sys.uptime / 60 % 60); +#endif if (show_colors) printf("\033[18C%s%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\n", BOLD, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, NORMAL); @@ -350,13 +350,15 @@ void get_info() break; } else if (library) // macOS - { - closedir(library); - sysctlbyname("machdep.cpu.brand_string", &cpu_buffer, &cpu_buffer_len, NULL, 0); + { + closedir(library); +#ifdef __APPLE__ + sysctlbyname("machdep.cpu.brand_string", &cpu_buffer, &cpu_buffer_len, NULL, 0); - sprintf(version_name, "macos"); - sprintf(cpu_model, "%s", cpu_buffer); - } + sprintf(version_name, "macos"); + sprintf(cpu_model, "%s", cpu_buffer); +#endif + } else sprintf(version_name, "unknown"); } @@ -371,7 +373,7 @@ void get_info() // system resources uname(&sys_var); - sysinfo(&sys); // somehow this function has to be called again in print_info() + sysinfo(&sys); // somehow this function has to be called again in print_info() truncate_name(sys_var.release); sprintf(kernel, "%s %s %s", sys_var.sysname, sys_var.release, sys_var.machine); @@ -400,18 +402,24 @@ void get_info() fclose(meminfo); #else // Used - FILE *mem_wired_fp, *mem_active_fp, *mem_compressed_fp; + FILE *mem_wired_fp, *mem_active_fp, *mem_compressed_fp; mem_wired_fp = popen("vm_stat | awk '/wired/ { printf $4 }' | cut -d '.' -f 1", "r"); mem_active_fp = popen("vm_stat | awk '/active/ { printf $3 }' | cut -d '.' -f 1", "r"); mem_compressed_fp = popen("vm_stat | awk '/occupied/ { printf $5 }' | cut -d '.' -f 1", "r"); char mem_wired_ch[2137], mem_active_ch[2137], mem_compressed_ch[2137]; - while(fgets(mem_wired_ch, sizeof(mem_wired_ch), mem_wired_fp) != NULL) { - while(fgets(mem_active_ch, sizeof(mem_active_ch), mem_active_fp) != NULL) { - while(fgets(mem_compressed_ch, sizeof(mem_compressed_ch), mem_compressed_fp) != NULL) {} + while (fgets(mem_wired_ch, sizeof(mem_wired_ch), mem_wired_fp) != NULL) + { + while (fgets(mem_active_ch, sizeof(mem_active_ch), mem_active_fp) != NULL) + { + while (fgets(mem_compressed_ch, sizeof(mem_compressed_ch), mem_compressed_fp) != NULL) + { + } } } - pclose(mem_wired_fp); pclose(mem_active_fp); pclose(mem_compressed_fp); + pclose(mem_wired_fp); + pclose(mem_active_fp); + pclose(mem_compressed_fp); int mem_wired = atoi(mem_wired_ch); int mem_active = atoi(mem_active_ch); @@ -440,12 +448,12 @@ void get_info() // get gpus with lspci command if (strcmp(version_name, "android") != 0) { - #ifndef __APPLE__ - gpu = popen("lspci -mm 2> /dev/null | grep \"VGA\" | cut --fields=4,6 -d '\"' --output-delimiter=\" \" | sed \"s/ Controller.*//\"", "r"); - #else - gpu = popen("system_profiler SPDisplaysDataType | awk -F ': ' '/Chipset Model: /{ print $2 }'", "r"); - #endif - } +#ifndef __APPLE__ + gpu = popen("lspci -mm 2> /dev/null | grep \"VGA\" | cut --fields=4,6 -d '\"' --output-delimiter=\" \" | sed \"s/ Controller.*//\"", "r"); +#else + gpu = popen("system_profiler SPDisplaysDataType | awk -F ': ' '/Chipset Model: /{ print $2 }'", "r"); +#endif + } else gpu = popen("getprop ro.hardware.vulkan 2> /dev/null", "r"); } @@ -690,15 +698,16 @@ void print_ascii() } else if (strcmp(version_name, "macos") == 0) - { - printf("\033[1E\033[3C%s .:`\n" - " .--``--.\n" - "%s ww OwO w\n" - "%s w w\n" - "%s w w\n" - "%s w w\n" - " www_-_www\n\n", GREEN, YELLOW, RED, PINK, BLUE); - } + { + printf("\033[1E\033[3C%s .:`\n" + " .--``--.\n" + "%s ww OwO w\n" + "%s w w\n" + "%s w w\n" + "%s w w\n" + " www_-_www\n\n", + GREEN, YELLOW, RED, PINK, BLUE); + } // everything else else