Simplified "+help" binding by using a temp file and run_script()

This commit is contained in:
Bruce Hill 2019-11-11 10:25:15 -08:00
parent d4f887d853
commit 000b652ac0

30
bb.c
View File

@ -663,28 +663,14 @@ void run_bbcmd(bb_t *bb, const char *cmd)
set_cursor(bb, e->index); set_cursor(bb, e->index);
else try_free_entry(e); else try_free_entry(e);
} else if (matches_cmd(cmd, "help")) { // +help } else if (matches_cmd(cmd, "help")) { // +help
restore_term(&default_termios); char filename[256] = "/tmp/bbhelp.XXXXXX";
int fds[2]; int fd = mkostemp(filename, O_WRONLY);
pipe(fds); print_bindings(fd);
proc_t *proc = memcheck(calloc(1, sizeof(proc_t))); close(fd);
if ((proc->pid = fork()) == 0) { char script[512] = "less -rKX < ";
fclose(tty_out); tty_out = NULL; strcat(script, filename);
fclose(tty_in); tty_in = NULL; run_script(bb, script);
setpgid(0, 0); unlink(filename);
close(fds[1]);
dup2(fds[0], STDIN_FILENO);
char *args[] = {SH, "-c", "less -rKX", NULL};
execvp(SH, args);
}
LL_PREPEND(running_procs, proc, running);
signal(SIGTTOU, SIG_IGN);
tcsetpgrp(fileno(tty_out), proc->pid);
close(fds[0]);
print_bindings(fds[1]);
close(fds[1]);
wait_for_process(&proc);
init_term();
dirty = 1;
} else if (matches_cmd(cmd, "interleave:") || matches_cmd(cmd, "interleave")) { // +interleave } else if (matches_cmd(cmd, "interleave:") || matches_cmd(cmd, "interleave")) { // +interleave
set_bool(bb->interleave_dirs); set_bool(bb->interleave_dirs);
sort_files(bb); sort_files(bb);