mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Support NOICE_OPENER env variable.
This commit is contained in:
parent
46e8388784
commit
8b12ac4b5c
27
noice.c
27
noice.c
|
@ -38,7 +38,7 @@
|
||||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||||
#define ISODD(x) ((x) & 1)
|
#define ISODD(x) ((x) & 1)
|
||||||
#define CONTROL(c) ((c) ^ 0x40)
|
#define CONTROL(c) ((c) ^ 0x40)
|
||||||
#define MAX_PATH_LEN 1024
|
#define MAX_LEN 1024
|
||||||
|
|
||||||
struct assoc {
|
struct assoc {
|
||||||
char *regex; /* Regex to match on filename */
|
char *regex; /* Regex to match on filename */
|
||||||
|
@ -85,6 +85,7 @@ struct entry {
|
||||||
struct entry *dents;
|
struct entry *dents;
|
||||||
int ndents, cur;
|
int ndents, cur;
|
||||||
int idle;
|
int idle;
|
||||||
|
char *opener = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Layout:
|
* Layout:
|
||||||
|
@ -652,19 +653,32 @@ nochange:
|
||||||
strlcpy(fltr, ifilter, sizeof(fltr));
|
strlcpy(fltr, ifilter, sizeof(fltr));
|
||||||
goto begin;
|
goto begin;
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
|
/* If default mime opener is set, use it */
|
||||||
|
if (opener) {
|
||||||
|
char cmd[MAX_LEN];
|
||||||
|
int status;
|
||||||
|
|
||||||
|
snprintf(cmd, MAX_LEN, "%s \"%s\" > /dev/null 2>&1", opener, newpath);
|
||||||
|
status = system(cmd);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try custom applications */
|
||||||
bin = openwith(newpath);
|
bin = openwith(newpath);
|
||||||
char *execvim = "vim";
|
char *execvim = "vim";
|
||||||
|
|
||||||
if (bin == NULL) {
|
if (bin == NULL) {
|
||||||
|
/* If a custom hander application is not set, open
|
||||||
|
plain text files with vim, then try xdg-open */
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char cmd[MAX_PATH_LEN];
|
char cmd[MAX_LEN];
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
snprintf(cmd, MAX_PATH_LEN, "file \"%s\"", newpath);
|
snprintf(cmd, MAX_LEN, "file \"%s\"", newpath);
|
||||||
fp = popen(cmd, "r");
|
fp = popen(cmd, "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
goto nochange;
|
goto nochange;
|
||||||
if (fgets(cmd, MAX_PATH_LEN, fp) == NULL) {
|
if (fgets(cmd, MAX_LEN, fp) == NULL) {
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
@ -673,7 +687,7 @@ nochange:
|
||||||
if (strstr(cmd, "ASCII text") != NULL)
|
if (strstr(cmd, "ASCII text") != NULL)
|
||||||
bin = execvim;
|
bin = execvim;
|
||||||
else {
|
else {
|
||||||
snprintf(cmd, MAX_PATH_LEN, "xdg-open \"%s\" > /dev/null 2>&1", newpath);
|
snprintf(cmd, MAX_LEN, "xdg-open \"%s\" > /dev/null 2>&1", newpath);
|
||||||
status = system(cmd);
|
status = system(cmd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -832,6 +846,9 @@ main(int argc, char *argv[])
|
||||||
ipath = "/";
|
ipath = "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the default desktop mime opener, if set */
|
||||||
|
opener = getenv("NOICE_OPENER");
|
||||||
|
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
|
|
||||||
/* Test initial path */
|
/* Test initial path */
|
||||||
|
|
Loading…
Reference in a new issue