]> git.sur5r.net Git - i3/i3status/blobdiff - src/auto_detect_format.c
Bugfix: output auto detect: properly detect ambiguous situations (Thanks mist)
[i3/i3status] / src / auto_detect_format.c
index b8dfdfc0231b92ee052fcc62917e37bcb93c76cd..6ec5f731d906eb1269c2bdc2b26fd23a39439914 100644 (file)
@@ -29,7 +29,7 @@
  * We then check whether the pipe target’s name is known and chose the format.
  *
  */
-char *auto_detect_format() {
+char *auto_detect_format(void) {
     pid_t myppid = getppid();
     pid_t mypid = getpid();
 
@@ -74,6 +74,19 @@ char *auto_detect_format() {
     if (!parentname)
         goto out;
 
+    /* Some shells, for example zsh, open a pipe in a way which will make the
+     * pipe target the parent process of i3status. If we detect that, we set
+     * the format and we are done. */
+    if (strcasecmp(parentname, "i3bar") == 0)
+        format = "i3bar";
+    else if (strcasecmp(parentname, "dzen2") == 0)
+        format = "dzen2";
+    else if (strcasecmp(parentname, "xmobar") == 0)
+        format = "xmobar";
+
+    if (format)
+        goto out;
+
     rewinddir(dir);
 
     while ((entry = readdir(dir)) != NULL) {
@@ -120,13 +133,13 @@ char *auto_detect_format() {
         /* Check for known destination programs and set format */
         char *newfmt = NULL;
         if (strcasecmp(name, "i3bar") == 0)
-            newfmt = "none";
+            newfmt = "i3bar";
         else if (strcasecmp(name, "dzen2") == 0)
             newfmt = "dzen2";
         else if (strcasecmp(name, "xmobar") == 0)
             newfmt = "xmobar";
 
-        if (newfmt && format) {
+        if (newfmt && format && strcmp(newfmt, format) != 0) {
             fprintf(stderr, "i3status: cannot auto-configure, situation ambiguous (format \"%s\" *and* \"%s\" detected)\n", newfmt, format);
             format = NULL;
             break;
@@ -136,6 +149,9 @@ char *auto_detect_format() {
     }
 
 out:
+    if (parentname)
+        free(parentname);
+
     closedir(dir);
 
     return format;