From cf03a230b61380de4418a5439b6649bcbf516c09 Mon Sep 17 00:00:00 2001 From: nova Date: Wed, 3 Jun 2026 23:00:06 +0200 Subject: [PATCH] implementation of open_with --- config.h | 2 +- interactions.c | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index 145feb2..9182073 100644 --- a/config.h +++ b/config.h @@ -68,7 +68,7 @@ static const binding key_binding[] = { { "n", move_up, NULL, "move up" }, { "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */ - { "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */ + { "\n", open_with, NULL, "open \"open with\" dialog" }, /* execute shell cmd on file, accounts for SETTINGS_COMMAND_FORK */ { "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */ { "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory * this means that it does not delete the hovered files if files are already selected */ diff --git a/interactions.c b/interactions.c index 0d4b501..f617033 100644 --- a/interactions.c +++ b/interactions.c @@ -281,7 +281,31 @@ void jump_top(){ status |= (STATUS_RUN_BACKEND); } void open_with(){ - TODO; + wclear(win_b); + char *cmd; + char *str = malloc(INPUT_BUFFER_SIZE); + char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file); + mvwprintw(win_b, 0, 0, parsed_ui_text); + if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) { + if (str[0] == SETTINGS_COMMAND_FORK) { + cmd = parse_cmd(str+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(str, mid_dir.current_file); + if (system(cmd)) { + } + } + free(cmd); + } + free(parsed_ui_text); + free(str); + status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR); + } void rename_hovered(){ wclear(win_b);