]> Sergey Matveev's repositories - nnn.git/commitdiff
Modify file type handling.
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 20 Aug 2016 14:35:35 +0000 (20:05 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 20 Aug 2016 14:35:35 +0000 (20:05 +0530)
Use mpv, fmedia, zathura.
Invoke libmagic to identify text files and open with vim.
Use xdg-open for unhandled mimes.

Makefile
config.def.h
noice.c

index 9035141dc902cc4b912f7446f96a4308d413b687..ed7a2c4ec643cb70d1e2b766c4a63d3cdca313f2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,8 @@ MANPREFIX = $(PREFIX)/man
 
 #CPPFLAGS = -DDEBUG
 #CFLAGS = -g
-LDLIBS = -lcurses
+CFLAGS = -O3 -march=native
+LDLIBS = -lcurses -lmagic
 
 DISTFILES = noice.c strlcat.c strlcpy.c util.h config.def.h\
     noice.1 Makefile README LICENSE
index af9bcbb641d49dafcc68ab448ff7e27be1199936..b9f6741b4c7c165358ca3579899e9d58645557a7 100644 (file)
@@ -8,12 +8,13 @@ int idletimeout = 0; /* Screensaver timeout in seconds, 0 to disable */
 char *idlecmd = "rain"; /* The screensaver program */
 
 struct assoc assocs[] = {
-       { "\\.(avi|mp4|mkv|mp3|ogg|flac|mov)$", "mplayer" },
-       { "\\.(png|jpg|gif)$", "feh" },
-       { "\\.(html|svg)$", "firefox" },
-       { "\\.pdf$", "mupdf" },
+       //{ "\\.(avi|mp4|mkv|mp3|ogg|flac|mov)$", "mpv" },
+       { "\\.(wma|mp3|ogg|flac)$", "fmedia" },
+       //{ "\\.(png|jpg|gif)$", "feh" },
+       //{ "\\.(html|svg)$", "firefox" },
+       { "\\.pdf$", "zathura" },
        { "\\.sh$", "sh" },
-       { ".", "less" },
+       //{ ".", "less" },
 };
 
 struct key bindings[] = {
diff --git a/noice.c b/noice.c
index a588a55cede83b485cd0c2758cdca7b26cb275db..4db6f7f1d211f547668b3bb7a4cbf04e195da93b 100644 (file)
--- a/noice.c
+++ b/noice.c
@@ -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(&regex, 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;
                                }