]> Sergey Matveev's repositories - nnn.git/commitdiff
Detect filetype using file output
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 4 Dec 2018 23:10:01 +0000 (04:40 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 4 Dec 2018 23:10:01 +0000 (04:40 +0530)
src/nnn.c
src/nnn.h

index 7d387ff1eb7b92ea4b806204c5cf65960048490a..4986d06ba1417114dc4b1a88d558f4f1c7e471b8 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -987,26 +987,6 @@ static char xchartohex(char c)
        return c;
 }
 
-static char *getmime(const char *file)
-{
-       static regex_t regex;
-       static uint i;
-       static const uint len = LEN(assocs);
-
-       for (i = 0; i < len; ++i) {
-               if (regcomp(&regex, assocs[i].regex, REG_NOSUB | REG_EXTENDED | REG_ICASE) != 0)
-                       continue;
-
-               if (regexec(&regex, file, 0, NULL, 0) == 0) {
-                       regfree(&regex);
-                       return assocs[i].mime;
-               }
-       }
-
-       regfree(&regex);
-       return NULL;
-}
-
 static int setfilter(regex_t *regex, char *filter)
 {
        static size_t len;
@@ -2719,13 +2699,12 @@ nochange:
                                        continue;
 
                                /* If NNN_USE_EDITOR is set, open text in EDITOR */
-                               if (cfg.useeditor)
-                                       if (getmime(dents[cur].name) ||
-                                           (get_output(g_buf, CMD_LEN_MAX, "file", FILE_OPTS, newpath, FALSE) &&
-                                            strstr(g_buf, "text/") == g_buf)) {
-                                               spawn(editor, newpath, editor_arg, path, F_NORMAL);
-                                               continue;
-                                       }
+                               if (cfg.useeditor &&
+                                   get_output(g_buf, CMD_LEN_MAX, "file", FILE_OPTS, newpath, FALSE) &&
+                                   strstr(g_buf, "text/") == g_buf) {
+                                       spawn(editor, newpath, editor_arg, path, F_NORMAL);
+                                       continue;
+                               }
 
                                /* Invoke desktop opener as last resort */
                                spawn(utils[OPENER], newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
index c9a6d6fd847c78b7ece773137d523373cd24c83e..aeccd4f59bd81542799e2927639cfffbe08d9ae5 100644 (file)
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -96,16 +96,6 @@ struct key {
        enum action act; /* Action */
 };
 
-/* Extension pattern and mime combination */
-struct assoc {
-       char *regex; /* Regex to match on filename */
-       char *mime;  /* File type */
-};
-
-static struct assoc assocs[] = {
-       { "\\.(c|cpp|h|log|md|py|rb|sh|txt)$", "text" },
-};
-
 static struct key bindings[] = {
        /* Back */
        { KEY_BACKSPACE,  SEL_BACK },