aboutsummaryrefslogtreecommitdiffstats
path: root/keys.c
diff options
context:
space:
mode:
authorverdant <im@verdant.ee>2026-07-28 14:46:43 +0800
committerverdant <im@verdant.ee>2026-07-28 14:46:43 +0800
commitfe423ed2794273445ad51332d08b19155bcbc3e8 (patch)
treecb14719d9aba6b531c253c96856e49c479258634 /keys.c
parent81f3312cc234af234d325f40362e08777a4ffe35 (diff)
downloadsf-fe423ed2794273445ad51332d08b19155bcbc3e8.tar.gz
sf-fe423ed2794273445ad51332d08b19155bcbc3e8.zip
Implement open with editor
Fork a child process to run the text editor. If the "EDITOR" envrionment variable is not set, fallback to "vi".
Diffstat (limited to 'keys.c')
-rw-r--r--keys.c24
1 files changed, 24 insertions, 0 deletions
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 <linux/limits.h>
#include <ncurses.h>
+#include <stdio.h>
#include <stdlib.h>
#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;
}