+/* ram used */
+char *
+ram_used(const char *null)
+{
+ long free, total, buffers, cached, used;
+ FILE *fp;
+
+ /* open meminfo file */
+ if (!(fp = fopen("/proc/meminfo", "r"))) {
+ fprintf(stderr, "Error opening meminfo file.");
+ return smprintf("n/a");
+ }
+
+ /* read the values */
+ fscanf(fp, "MemTotal: %ld kB\n", &total);
+ fscanf(fp, "MemFree: %ld kB\n", &free);
+ fscanf(fp, "MemAvailable: %ld kB\nBuffers: %ld kB\n", &buffers, &buffers);
+ fscanf(fp, "Cached: %ld kB\n", &cached);
+
+ /* close meminfo file */
+ fclose(fp);
+
+ /* calculate used */
+ used = total - free - buffers - cached;
+
+ /* return used ram as string */
+ 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 */
+char *
+temp(const char *file)
+{
+ int temperature;
+ FILE *fp;
+
+ /* open temperature file */
+ if (!(fp = fopen(file, "r"))) {
+ fprintf(stderr, "Could not open temperature file.\n");
+ return smprintf("n/a");
+ }
+
+ /* extract temperature */
+ fscanf(fp, "%d", &temperature);
+
+ /* close temperature file */
+ fclose(fp);
+
+ /* return temperature in degrees */
+ return smprintf("%d°C", temperature / 1000);
+}
+
+/* username */