diff --git a/config.h b/config.h index 7016725..122b3c6 100644 --- a/config.h +++ b/config.h @@ -2,6 +2,7 @@ #include "interactions.h" #include "sorting.h" + static const mimetype mimetype_default_cmd[] = { /* mimetype shell command * ^ substring of "file --mime-type -b ./hovered" @@ -16,7 +17,12 @@ static const mimetype mimetype_default_cmd[] = { { "video", "mpv" }, { "audio", "mpv" } }; - +static const extension file_extension_default_cmd[] = { + /* extension shell command + * similar to mimetype_default_cmd, however it searches for exact string matches + * and is checked before mimetype_default_cmd */ + { ".exe", "wine"}, +}; static const binding key_binding[] = { /*key action blackmagic comment*/ /*you cannot add bindings that include other bindings in its entirety @@ -72,3 +78,4 @@ static const binding key_binding[] = { }; static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding); static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype); +static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension); diff --git a/defines.h b/defines.h index e77e7b0..e3de1ee 100644 --- a/defines.h +++ b/defines.h @@ -71,6 +71,10 @@ typedef struct Mimetype { char *mimetype; char *command; } mimetype; +typedef struct Extension { + char *file_extension; + char *command; +} extension; typedef struct Binding { char* key; void (*func)(); diff --git a/interactions.c b/interactions.c index 4af8ed8..423f8f9 100644 --- a/interactions.c +++ b/interactions.c @@ -238,11 +238,12 @@ void move_right(){ } } else { unsigned long i = 0; + char match = 0; char *mime = get_mimetype(file_current->file_name); - for (i = 0; i < mimetype_default_count; i++) { - if (strstr(mime, mimetype_default_cmd[i].mimetype)) { - - char *cmd = concat(mimetype_default_cmd[i].command, " ./\""); + char *extension = strrchr(file_current->file_name, '.'); + for (i = 0; i < file_extension_default_count; i++) { + if (strstr(extension, file_extension_default_cmd[i].file_extension)) { + char *cmd = concat(file_extension_default_cmd[i].command, " ./\""); cmd = concat(cmd, file_current->file_name); cmd = concat(cmd, "\""); btm_buffer = malloc(strlen(cmd)); @@ -253,12 +254,34 @@ void move_right(){ if (system(cmd) == -1) { /*do nothing*/ } + match = 1; status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); break; + } + } + if (match == 0) { + for (i = 0; i < mimetype_default_count; i++) { + if (strstr(mime, mimetype_default_cmd[i].mimetype)) { + char *cmd = concat(mimetype_default_cmd[i].command, " ./\""); + cmd = concat(cmd, file_current->file_name); + cmd = concat(cmd, "\""); + btm_buffer = malloc(strlen(cmd)); + + strcpy(btm_buffer, cmd-1); + + + if (system(cmd) == -1) { + /*do nothing*/ + } + status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); + break; + + } } } free(mime); + free(extension); } status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); }