]> Sergey Matveev's repositories - nnn.git/commitdiff
Try fallbak for missing apps, use popen wrapper
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 5 Apr 2017 16:48:21 +0000 (22:18 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Thu, 6 Apr 2017 00:59:18 +0000 (06:29 +0530)
nnn.c

diff --git a/nnn.c b/nnn.c
index aa332dc15b54f60ea1ecccabf7bf1f3e7e99d01e..b8aeb21fab979d9974fff7bc56fd932ef735ff9c 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -1141,7 +1141,6 @@ nochange:
                                static char cmd[MAX_CMD_LEN];
                                static char *runvi = "vi";
                                static int status;
-                               static FILE *fp;
 
                                /* If default mime opener is set, use it */
                                if (opener) {
@@ -1155,20 +1154,19 @@ nochange:
                                /* Try custom applications */
                                bin = openwith(newpath);
 
+                               /* If custom app doesn't exist try fallback */
+                               snprintf(cmd, MAX_CMD_LEN, "which \"%s\"", bin);
+                               if (get_output(cmd, MAX_CMD_LEN) == NULL)
+                                       bin = NULL;
+
                                if (bin == NULL) {
                                        /* If a custom handler application is
                                           not set, open plain text files with
                                           vi, then try fallback_opener */
                                        snprintf(cmd, MAX_CMD_LEN,
                                                 "file \"%s\"", newpath);
-                                       fp = popen(cmd, "r");
-                                       if (fp == NULL)
-                                               goto nochange;
-                                       if (fgets(cmd, MAX_CMD_LEN, fp) == NULL) {
-                                               pclose(fp);
+                                       if (get_output(cmd, MAX_CMD_LEN) == NULL)
                                                goto nochange;
-                                       }
-                                       pclose(fp);
 
                                        if (strstr(cmd, "ASCII text") != NULL)
                                                bin = runvi;