This commit is contained in:
Your Name 2023-11-02 18:19:43 +03:00
parent 135a196f9a
commit dfa1d3ad24
3 changed files with 44 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}