From fe423ed2794273445ad51332d08b19155bcbc3e8 Mon Sep 17 00:00:00 2001 From: verdant Date: Tue, 28 Jul 2026 14:46:43 +0800 Subject: Implement open with editor Fork a child process to run the text editor. If the "EDITOR" envrionment variable is not set, fallback to "vi". --- keys.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'keys.c') diff --git a/keys.c b/keys.c index a954794..8fa11c6 100644 --- a/keys.c +++ b/keys.c @@ -1,11 +1,15 @@ #include "keys.h" +#include #include +#include #include #include "display.h" +#include "err.h" #include "fm.h" #include "log.h" +#include "mem.h" #include "wm.h" void handling_keys(int ch, fm_info *i) @@ -34,7 +38,27 @@ void handling_keys(int ch, fm_info *i) case 'l': fm_cd_down(i); break; + case 'o': + case '\n': + case '\r': + case KEY_ENTER: + log_write(LOG_INFO, "Open file"); + if (!(i->cur->items[i->cursor].is_dir)) { + char filepath[PATH_MAX]; + size_t len = + snprintf(filepath, PATH_MAX, "%s/%s", i->cwd, + i->cur->items[i->cursor].name); + if (len >= PATH_MAX) { + die("snprintf failed"); + } + char *argv[] = {enveditor, filepath, NULL}; + open_with_editor(argv); + break; + } else { + return; + } + break; default: return; } -- cgit v1.2.3