fix
This commit is contained in:
parent
135a196f9a
commit
dfa1d3ad24
13
config.h
13
config.h
@ -13,11 +13,14 @@ typedef struct {
|
|||||||
#define PC_CHAR "%"
|
#define PC_CHAR "%"
|
||||||
|
|
||||||
static PARAMETR CONFIG[] = {
|
static PARAMETR CONFIG[] = {
|
||||||
{"Krnl ", GetKernel},
|
{"Os > ", PrintOs},
|
||||||
{"User ", GetUser},
|
{"Krnl > ", GetKernel},
|
||||||
{"Os ", PrintOs},
|
{"User > ", GetUser},
|
||||||
{" ", Blank},
|
{"Uptm > ", GetUptime},
|
||||||
{" ", PrintColors}
|
{"Arch > ", GetArch},
|
||||||
|
{"Shll > ", GetShell},
|
||||||
|
{" ", Blank},
|
||||||
|
{" ", PrintColors}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,5 +31,8 @@ void PrintOs(const char *title, const FETCH fetch);
|
|||||||
void PrintColors(const char *title, const FETCH fetch);
|
void PrintColors(const char *title, const FETCH fetch);
|
||||||
void Blank(const char *title, const FETCH fetch);
|
void Blank(const char *title, const FETCH fetch);
|
||||||
void GetUser(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
|
#endif
|
||||||
|
33
src/fetch.c
33
src/fetch.c
@ -83,3 +83,36 @@ void GetUser(const char *title, const FETCH fetch) {
|
|||||||
struct passwd *pw = getpwuid(geteuid());
|
struct passwd *pw = getpwuid(geteuid());
|
||||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, (pw != 0) ? pw->pw_name : "none");
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user