Added shell command function
This commit is contained in:
parent
3c1a03919f
commit
f6f0c895ce
|
@ -11,6 +11,7 @@ The following information is included:
|
||||||
|
|
||||||
- battery percentage
|
- battery percentage
|
||||||
- cpu usage (in percent)
|
- cpu usage (in percent)
|
||||||
|
- custom shell commands
|
||||||
- date and time
|
- date and time
|
||||||
- disk numbers (free storage, percentage, total storage and used storage)
|
- disk numbers (free storage, percentage, total storage and used storage)
|
||||||
- available entropy
|
- available entropy
|
||||||
|
|
|
@ -27,6 +27,7 @@ static unsigned int update_interval = 1;
|
||||||
- ram_perc (ram usage in percent) [argument: NULL]
|
- ram_perc (ram usage in percent) [argument: NULL]
|
||||||
- ram_total (ram usage in percent) [argument: NULL]
|
- ram_total (ram usage in percent) [argument: NULL]
|
||||||
- ram_used (ram usage in percent) [argument: NULL]
|
- ram_used (ram usage in percent) [argument: NULL]
|
||||||
|
- run_command (run custom shell command) [argument: command]
|
||||||
- temp (temperature in degrees) [argument: temperature file]
|
- temp (temperature in degrees) [argument: temperature file]
|
||||||
- uid (uid of current user) [argument: NULL]
|
- uid (uid of current user) [argument: NULL]
|
||||||
- username (username of current user) [argument: NULL]
|
- username (username of current user) [argument: NULL]
|
||||||
|
|
26
slstatus.c
26
slstatus.c
|
@ -444,6 +444,32 @@ ram_used(const char *null)
|
||||||
return smprintf("%f", (float)used / 1024 / 1024);
|
return smprintf("%f", (float)used / 1024 / 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* custom shell command */
|
||||||
|
char *
|
||||||
|
run_command(const char* command)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char buffer[64];
|
||||||
|
|
||||||
|
/* try to open the command output */
|
||||||
|
if (!(fp = popen(command, "r"))) {
|
||||||
|
fprintf(stderr, "Could not get command output for: %s.\n", command);
|
||||||
|
return smprintf("n/a");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get command output text, save it to buffer */
|
||||||
|
fgets(buffer, sizeof(buffer)-1, fp);
|
||||||
|
|
||||||
|
/* close it again */
|
||||||
|
pclose(fp);
|
||||||
|
|
||||||
|
/* add nullchar at the end */
|
||||||
|
buffer[strlen(buffer) - 1] = '\0';
|
||||||
|
|
||||||
|
/* return the output */
|
||||||
|
return smprintf("%s", buffer);
|
||||||
|
}
|
||||||
|
|
||||||
/* temperature */
|
/* temperature */
|
||||||
char *
|
char *
|
||||||
temp(const char *file)
|
temp(const char *file)
|
||||||
|
|
Loading…
Reference in New Issue