diff options
Diffstat (limited to 'noice.c')
| -rw-r--r-- | noice.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -17,6 +17,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <magic.h> #include "util.h" @@ -207,6 +208,20 @@ openwith(char *file) char *bin = NULL; int i; + const char *mime; + magic_t magic; + + magic = magic_open(MAGIC_MIME_TYPE); + magic_load(magic, NULL); + magic_compile(magic, NULL); + mime = magic_file(magic, file); + DPRINTF_S(mime); + + if (strcmp(mime, "text/plain") == 0) + magic_close(magic); + return "vim"; + magic_close(magic); + for (i = 0; i < LEN(assocs); i++) { if (regcomp(®ex, assocs[i].regex, REG_NOSUB | REG_EXTENDED | REG_ICASE) != 0) @@ -650,6 +665,9 @@ nochange: case S_IFREG: bin = openwith(newpath); if (bin == NULL) { + char cmd[512]; + sprintf(cmd, "xdg-open \"%s\" > /dev/null 2>&1", newpath); + system(cmd); printmsg("No association"); goto nochange; } |