+/* custom shell command */
+char *
+run_command(const char* command)
+{
+ int good;
+ 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 */
+ for (int i = 0 ; i != sizeof(buffer); i++) {
+ if (buffer[i] == '\0') {
+ good = 1;
+ break;
+ }
+ }
+ if (good) {
+ 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 */
+char *
+username(const char *null)
+{
+ register struct passwd *pw;
+ register uid_t uid;
+
+ /* get the values */
+ uid = geteuid();
+ pw = getpwuid(uid);
+
+ /* if it worked, return */
+ if (pw) {
+ return smprintf("%s", pw->pw_name);
+ } else {
+ fprintf(stderr, "Could not get username.\n");
+ return smprintf("n/a");
+ }
+
+ return smprintf("n/a");
+}
+
+/* uid */
+char *
+uid(const char *null)
+{
+ register uid_t uid;
+
+ /* get the values */
+ uid = geteuid();
+
+ /* if it worked, return */
+ if (uid) {
+ return smprintf("%d", uid);
+ } else {
+ fprintf(stderr, "Could not get uid.\n");
+ return smprintf("n/a");
+ }
+
+ return smprintf("n/a");
+}
+
+