aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-04-05 22:18:21 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-04-06 06:29:18 +0530
commit205dd6db0596d22b89394edabf40b4111f350e95 (patch)
treeb9478bf3863e649ec3401aaddbc0b70059311e00
parentb7e4968a488b2718c11c7468d393102785865b43 (diff)
downloadnnn-205dd6db0596d22b89394edabf40b4111f350e95.tar.gz
Try fallbak for missing apps, use popen wrapper
-rw-r--r--nnn.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/nnn.c b/nnn.c
index aa332dc..b8aeb21 100644
--- 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;