added file extension commands
This commit is contained in:
9
config.h
9
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);
|
||||
|
@ -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)();
|
||||
|
@ -238,7 +238,28 @@ void move_right(){
|
||||
}
|
||||
} else {
|
||||
unsigned long i = 0;
|
||||
char match = 0;
|
||||
char *mime = get_mimetype(file_current->file_name);
|
||||
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));
|
||||
|
||||
strcpy(btm_buffer, cmd-1);
|
||||
|
||||
|
||||
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)) {
|
||||
|
||||
@ -258,7 +279,9 @@ void move_right(){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
free(mime);
|
||||
free(extension);
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
|
Reference in New Issue
Block a user