From dfa1d3ad24427748a5b5870801d0c295571ce4ba Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 2 Nov 2023 18:19:43 +0300 Subject: [PATCH] fix --- config.h | 13 ++++++++----- include/fetch.h | 3 +++ src/fetch.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/config.h b/config.h index c44c562..84f490a 100644 --- a/config.h +++ b/config.h @@ -13,11 +13,14 @@ typedef struct { #define PC_CHAR "%" static PARAMETR CONFIG[] = { - {"Krnl ", GetKernel}, - {"User ", GetUser}, - {"Os ", PrintOs}, - {" ", Blank}, - {" ", PrintColors} + {"Os > ", PrintOs}, + {"Krnl > ", GetKernel}, + {"User > ", GetUser}, + {"Uptm > ", GetUptime}, + {"Arch > ", GetArch}, + {"Shll > ", GetShell}, + {" ", Blank}, + {" ", PrintColors} }; #endif diff --git a/include/fetch.h b/include/fetch.h index f5dbfa7..fb18d77 100644 --- a/include/fetch.h +++ b/include/fetch.h @@ -31,5 +31,8 @@ void PrintOs(const char *title, const FETCH fetch); void PrintColors(const char *title, const FETCH fetch); void Blank(const char *title, const FETCH fetch); void GetUser(const char *title, const FETCH fetch); +void GetUptime(const char *title, const FETCH fetch); +void GetArch(const char *title, const FETCH fetch); +void GetShell(const char *title, const FETCH fetch); #endif diff --git a/src/fetch.c b/src/fetch.c index 621a1a5..0276702 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -83,3 +83,36 @@ void GetUser(const char *title, const FETCH fetch) { struct passwd *pw = getpwuid(geteuid()); printf("%s%s%s%s", fetch.color, title, fetch.font_color, (pw != 0) ? pw->pw_name : "none"); } + +void GetUptime(const char *title, const FETCH fetch) { + int hours = 0; + int mins = 0; + +#ifdef CLOCK + struct timespec uptime; + clock_gettime(CLOCK, &uptime); + + hours = uptime.tv_sec / 3600; + mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60); +#endif + + printf("%s%s%s%dh %dm", fetch.color, title, fetch.font_color, hours, mins); +} + +void GetArch(const char *title, const FETCH fetch) { + printf("%s%s%s%s", fetch.color, title, fetch.font_color, fetch.uts.machine); +} + +void GetShell(const char *title, const FETCH fetch) { + char *shell = getenv("SHELL"); + if (shell == NULL) + printf("%s%s%s%s", fetch.color, title, fetch.font_color, "none"); + + char *splt = strrchr(shell, '/'); + if (splt == NULL) { + printf("%s%s%s%s", fetch.color, title, fetch.font_color, "none"); + return; + } + + printf("%s%s%s%s", fetch.color, title, fetch.font_color, splt + 1); +}