added file extension commands
This commit is contained in:
9
config.h
9
config.h
@ -2,6 +2,7 @@
|
|||||||
#include "interactions.h"
|
#include "interactions.h"
|
||||||
#include "sorting.h"
|
#include "sorting.h"
|
||||||
|
|
||||||
|
|
||||||
static const mimetype mimetype_default_cmd[] = {
|
static const mimetype mimetype_default_cmd[] = {
|
||||||
/* mimetype shell command
|
/* mimetype shell command
|
||||||
* ^ substring of "file --mime-type -b ./hovered"
|
* ^ substring of "file --mime-type -b ./hovered"
|
||||||
@ -16,7 +17,12 @@ static const mimetype mimetype_default_cmd[] = {
|
|||||||
{ "video", "mpv" },
|
{ "video", "mpv" },
|
||||||
{ "audio", "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[] = {
|
static const binding key_binding[] = {
|
||||||
/*key action blackmagic comment*/
|
/*key action blackmagic comment*/
|
||||||
/*you cannot add bindings that include other bindings in its entirety
|
/*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 binding_count = sizeof(key_binding) / sizeof(binding);
|
||||||
static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype);
|
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);
|
||||||
|
@ -71,6 +71,10 @@ typedef struct Mimetype {
|
|||||||
char *mimetype;
|
char *mimetype;
|
||||||
char *command;
|
char *command;
|
||||||
} mimetype;
|
} mimetype;
|
||||||
|
typedef struct Extension {
|
||||||
|
char *file_extension;
|
||||||
|
char *command;
|
||||||
|
} extension;
|
||||||
typedef struct Binding {
|
typedef struct Binding {
|
||||||
char* key;
|
char* key;
|
||||||
void (*func)();
|
void (*func)();
|
||||||
|
@ -238,11 +238,12 @@ void move_right(){
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
|
char match = 0;
|
||||||
char *mime = get_mimetype(file_current->file_name);
|
char *mime = get_mimetype(file_current->file_name);
|
||||||
for (i = 0; i < mimetype_default_count; i++) {
|
char *extension = strrchr(file_current->file_name, '.');
|
||||||
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
for (i = 0; i < file_extension_default_count; i++) {
|
||||||
|
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
||||||
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
|
char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
|
||||||
cmd = concat(cmd, file_current->file_name);
|
cmd = concat(cmd, file_current->file_name);
|
||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, "\"");
|
||||||
btm_buffer = malloc(strlen(cmd));
|
btm_buffer = malloc(strlen(cmd));
|
||||||
@ -253,12 +254,34 @@ void move_right(){
|
|||||||
if (system(cmd) == -1) {
|
if (system(cmd) == -1) {
|
||||||
/*do nothing*/
|
/*do nothing*/
|
||||||
}
|
}
|
||||||
|
match = 1;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
||||||
break;
|
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(mime);
|
||||||
|
free(extension);
|
||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user