Use mpv, fmedia, zathura. Invoke libmagic to identify text files and open with vim. Use xdg-open for unhandled mimes.master
@@ -5,7 +5,8 @@ MANPREFIX = $(PREFIX)/man | |||||
#CPPFLAGS = -DDEBUG | #CPPFLAGS = -DDEBUG | ||||
#CFLAGS = -g | #CFLAGS = -g | ||||
LDLIBS = -lcurses | CFLAGS = -O3 -march=native | ||||
LDLIBS = -lcurses -lmagic | |||||
DISTFILES = noice.c strlcat.c strlcpy.c util.h config.def.h\ | DISTFILES = noice.c strlcat.c strlcpy.c util.h config.def.h\ | ||||
noice.1 Makefile README LICENSE | noice.1 Makefile README LICENSE | ||||
@@ -8,12 +8,13 @@ int idletimeout = 0; /* Screensaver timeout in seconds, 0 to disable */ | |||||
char *idlecmd = "rain"; /* The screensaver program */ | char *idlecmd = "rain"; /* The screensaver program */ | ||||
struct assoc assocs[] = { | struct assoc assocs[] = { | ||||
{ "\\.(avi|mp4|mkv|mp3|ogg|flac|mov)$", "mplayer" }, | //{ "\\.(avi|mp4|mkv|mp3|ogg|flac|mov)$", "mpv" }, | ||||
{ "\\.(png|jpg|gif)$", "feh" }, | { "\\.(wma|mp3|ogg|flac)$", "fmedia" }, | ||||
{ "\\.(html|svg)$", "firefox" }, | //{ "\\.(png|jpg|gif)$", "feh" }, | ||||
{ "\\.pdf$", "mupdf" }, | //{ "\\.(html|svg)$", "firefox" }, | ||||
{ "\\.pdf$", "zathura" }, | |||||
{ "\\.sh$", "sh" }, | { "\\.sh$", "sh" }, | ||||
{ ".", "less" }, | //{ ".", "less" }, | ||||
}; | }; | ||||
struct key bindings[] = { | struct key bindings[] = { | ||||
@@ -17,6 +17,7 @@ | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <magic.h> | |||||
#include "util.h" | #include "util.h" | ||||
@@ -207,6 +208,20 @@ openwith(char *file) | |||||
char *bin = NULL; | char *bin = NULL; | ||||
int i; | 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++) { | for (i = 0; i < LEN(assocs); i++) { | ||||
if (regcomp(®ex, assocs[i].regex, | if (regcomp(®ex, assocs[i].regex, | ||||
REG_NOSUB | REG_EXTENDED | REG_ICASE) != 0) | REG_NOSUB | REG_EXTENDED | REG_ICASE) != 0) | ||||
@@ -650,6 +665,9 @@ nochange: | |||||
case S_IFREG: | case S_IFREG: | ||||
bin = openwith(newpath); | bin = openwith(newpath); | ||||
if (bin == NULL) { | if (bin == NULL) { | ||||
char cmd[512]; | |||||
sprintf(cmd, "xdg-open \"%s\" > /dev/null 2>&1", newpath); | |||||
system(cmd); | |||||
printmsg("No association"); | printmsg("No association"); | ||||
goto nochange; | goto nochange; | ||||
} | } | ||||