diff --git a/config.h b/config.h index b4f593d..9b1b87e 100644 --- a/config.h +++ b/config.h @@ -4,6 +4,7 @@ #define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */ #define SETTINGS_COMMAND_REPLACE_STR "^" /* if a command in any cmd inside this fle contains this string, it will be replaced with the hovered/selected file name * as of right now, this character cannot be escaped; i.e ``command\^ --arg`` will parse into ``command\path_of_hovered_file --arg``*/ +#define SETTINGS_COMMAND_FORK '@' /* commands starting with this character will be forked into a new non blokcing detached process */ /* {{{ */ #ifndef CONFIG_GUARD @@ -21,21 +22,21 @@ static const mimetype mimetype_default_cmd[] = { * file --mime-type -b ./image.gif * gives us "image/gif", thusly if we want to open gif in mpv rather than feh, * we need to define "gif" before "image" */ - { "text", "$EDITOR" }, - { "avif", "nohup mpv ^ >/dev/null 2>&1 &" }, - { "gif", "nohup mpv --loop-file=\"inf\" ^ >/dev/null 2>&1 &" }, - { "image", "feh ^ >/dev/null 2>&1 &" }, - { "video", "nohup mpv ^ >/dev/null 2>&1 &" }, - { "audio", "mpv" }, - { "pdf", "zathura" }, + { "text", "$EDITOR" }, + { "avif", "@ mpv" }, + { "gif", "@ mpv --loop-file=\"inf\"" }, + { "image", "@ feh" }, + { "video", "@ mpv" }, + { "audio", "mpv" }, + { "pdf", "@ zathura" }, }; 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"}, - { ".cbz", "mcomix ^ &"}, - { ".cbr", "mcomix ^ &"}, + { ".cbz", "@ mcomix"}, + { ".cbr", "@ mcomix"}, { ".json", "$EDITOR"}, { ".csv", "$EDITOR"}, { ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */ diff --git a/interactions.c b/interactions.c index b499253..97b7ccb 100644 --- a/interactions.c +++ b/interactions.c @@ -226,8 +226,18 @@ void move_right(){ if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) { for (i = 0; i < file_extension_default_count; i++) { if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) { - cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file); - if (system(cmd)) { + if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) { + cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file); + pid_t pid = fork(); + if (pid == 0 && setsid()) { + system(cmd); + status = STATUS_QUIT_PROGRAM; + exit(1); + } + } else { + cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file); + if (system(cmd)) { + } } status |= STATUS_MOVE_RIGHT_MATCH; update(); @@ -238,9 +248,20 @@ void move_right(){ if (!(status & STATUS_MOVE_RIGHT_MATCH)) { for (i = 0; i < mimetype_default_count; i++) { if (strstr(mime, mimetype_default_cmd[i].mimetype)) { - cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file); - if (system(cmd)) { + if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) { + cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file); + pid_t pid = fork(); + if (pid == 0 && setsid()) { + system(cmd); + status = STATUS_QUIT_PROGRAM; + exit(1); + } + } else { + cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file); + if (system(cmd)) { + } } + status |= STATUS_MOVE_RIGHT_MATCH; update(); break; }