Update 2.0

This commit is contained in:
Јован Ђокић-Шумарац 2021-05-26 20:10:19 +02:00
parent a3f473739e
commit cf0b593cef
2 changed files with 22 additions and 23 deletions

View file

@ -1,7 +1,8 @@
#+TITLE: Fetchy #+TITLE: Fetchy
Currently supported : Arch, Artix, Debian and Ubuntu. (more to come) Currently supported : Arch, Artix, Arco, Manjaro, Debian and Ubuntu. (more to come)
****TESTERS NEEDED****
* What is fetchy? * What is fetchy?
@ -11,9 +12,9 @@ Currently supported : Arch, Artix, Debian and Ubuntu. (more to come)
**** fetchy - simple cli system information tool written in C. **** fetchy - simple cli system information tool written in C.
The whole purpose of fetchy is to give you information on some system aspects, while remaining concise. It is minimal and soon will have a config.h file, similar to suckless programs, where you will be able to disable or enable info. The biggest motivation for this project, besides of being concise, is speed. Neofetch is a 10K line bash script which executes rather slowly. Fetchy runs fo about 20ms on first run and about 2ms on subsequent runs, due to caching of cpu and gpu info, as it is the slowest part of the program. Cache file is located in ~/.local/share/fetchy.cache
* Installation
* Install
** AUR ** AUR
@ -29,9 +30,10 @@ cd fetchy
sudo make install sudo make install
#+end_src #+end_src
* Run * Running
#+begin_src #+begin_src
fetchy fetchy -{x,a,r,m,u,d}
#+end_src #+end_src
Arguments are purely for testing purposes for now, all they do is change ascii art. Enjoy !

View file

@ -15,6 +15,7 @@
#define SUPPORTED_OS "xadurm" #define SUPPORTED_OS "xadurm"
#define ARCH_BASED "axmr" #define ARCH_BASED "axmr"
#define DEBIAN_BASED "du" #define DEBIAN_BASED "du"
#define OS_TABLE "a:Arch|x:Artix|r:Arco|m:Manjaro|u:Ubuntu|d:Debian"
//ascii art header file //ascii art header file
#include "logos.h" #include "logos.h"
@ -22,11 +23,11 @@
// standardish functions // standardish functions
void read_line(char x); void read_line(char x);
void cache_info(char **cpu_name, char **gpu, char *os_table); void cache_info(char **cpu_name, char **gpu);
static int count_files(DIR *package_dir); static int count_files(DIR *package_dir);
// 'get info' functions // 'get info' functions
static char *get_sys(char *s_os, char *os_name, char *os_table); static char *get_sys(char *s_os, char *os_name);
static char *get_kernel(char *kern_name); static char *get_kernel(char *kern_name);
static char *get_uptime(char *uptime); static char *get_uptime(char *uptime);
static char *get_RAM(char *ram_info); static char *get_RAM(char *ram_info);
@ -51,17 +52,17 @@ int main(int argc, char *argv[]){
char *os_name = NULL, char *os_name = NULL,
*cpu_name = NULL, *cpu_name = NULL,
*gpu = NULL, *gpu = NULL,
*os = malloc(BUF_SIZE), *s_os = SUPPORTED_OS,
*os_table = malloc(BUF_SIZE * 2), *os = malloc(BUF_SIZE);
*s_os = SUPPORTED_OS;
// if cache file exits, read it, otherwise cache info // if cache file exits, read it, otherwise cache info
cache_info(&cpu_name, &gpu, os_table); cache_info(&cpu_name, &gpu);
os = get_sys(s_os, os_name, os_table); os = get_sys(s_os, os_name);
// chack if custom ascii art argument is passed // check if custom ascii art argument is passed
if ( argv[1] != NULL ) { if ( argv[1] != NULL ) {
if ( strchr(SUPPORTED_OS, *(argv[1] + 1)) ) if ( strchr(SUPPORTED_OS, *(argv[1] + 1)) )
@ -81,7 +82,7 @@ int main(int argc, char *argv[]){
free(os_name); free(os_name);
free(cpu_name); free(cpu_name);
free(gpu); free(gpu);
free(os);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -130,7 +131,7 @@ void truncate_spaces(char *str) {
void cache_info(char **cpu_name, char **gpu, char *os_table) { void cache_info(char **cpu_name, char **gpu) {
char *cache_path = malloc(BUF_SIZE * 2); char *cache_path = malloc(BUF_SIZE * 2);
FILE *f_cache = NULL; FILE *f_cache = NULL;
@ -154,8 +155,6 @@ void cache_info(char **cpu_name, char **gpu, char *os_table) {
truncate_spaces(line); truncate_spaces(line);
snprintf(*gpu, BUF_SIZE * 4, "\x1b[36mGPU\x1b[0m -> %s", strchr(line, ':') +2); snprintf(*gpu, BUF_SIZE * 4, "\x1b[36mGPU\x1b[0m -> %s", strchr(line, ':') +2);
//get OS table
fgets(os_table, BUF_SIZE * 2, f_cache);
fclose(f_cache); fclose(f_cache);
free(line); free(line);
@ -174,7 +173,6 @@ void cache_info(char **cpu_name, char **gpu, char *os_table) {
// Write info to file // Write info to file
fprintf(f_cache, "CPU : %s\n", get_cpu(*cpu_name)); fprintf(f_cache, "CPU : %s\n", get_cpu(*cpu_name));
fprintf(f_cache, "GPU : %s\n", get_gpu(*gpu)); fprintf(f_cache, "GPU : %s\n", get_gpu(*gpu));
fprintf(f_cache, "a:Arch|x:Artix|r:Arco|m:Manjaro|u:Ubuntu|d:Debian\n");
fclose(f_cache); fclose(f_cache);
@ -186,7 +184,7 @@ void cache_info(char **cpu_name, char **gpu, char *os_table) {
printf("run program normally. Enjoy!\n\n"); printf("run program normally. Enjoy!\n\n");
cache_info(cpu_name, gpu, os_table); cache_info(cpu_name, gpu);
} }
free(cache_path); free(cache_path);
} }
@ -211,12 +209,11 @@ static int count_files(DIR *package_dir) {
static char *get_sys(char *s_os, char *os_name, char *os_table) { static char *get_sys(char *s_os, char *os_name) {
os_name = malloc(BUF_SIZE);
char *name = malloc(BUF_SIZE); char *name = malloc(BUF_SIZE);
FILE *f_sys_name = fopen("/etc/issue", "rt"); FILE *f_sys_name = fopen("/etc/issue", "rt");
os_name = malloc(BUF_SIZE);
if( f_sys_name == NULL ){ if( f_sys_name == NULL ){
fprintf(stderr, "\nCan't get os name\n"); fprintf(stderr, "\nCan't get os name\n");
@ -229,7 +226,7 @@ static char *get_sys(char *s_os, char *os_name, char *os_table) {
truncate_spaces(name); truncate_spaces(name);
sys = *(strstr(os_table, name) - 2); sys = *(strstr(OS_TABLE, name) - 2);
logo_number = (int) (strchr(s_os, sys) - s_os); logo_number = (int) (strchr(s_os, sys) - s_os);