diff options
| author | verdant <im@verdant.ee> | 2026-07-28 14:46:43 +0800 |
|---|---|---|
| committer | verdant <im@verdant.ee> | 2026-07-28 14:46:43 +0800 |
| commit | fe423ed2794273445ad51332d08b19155bcbc3e8 (patch) | |
| tree | cb14719d9aba6b531c253c96856e49c479258634 /keys.c | |
| parent | 81f3312cc234af234d325f40362e08777a4ffe35 (diff) | |
| download | sf-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.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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; } |
