commit b9a64d45f6bf202e384c314e9e8b2b303e5d4f49 from: Omar Polo via: Thomas Adam date: Tue Jun 04 11:18:04 2024 UTC wip'n'crude: open downloads with xdg-open commit - 7ddea6c5284750e02983e76f44f19c65e51c638a commit + b9a64d45f6bf202e384c314e9e8b2b303e5d4f49 blob - 57d01ea586adb3381066c9342720bcb3642f4165 blob + f137ba2586ebfbe7c474fbb7bb5b47c357206b4e --- cmd.c +++ cmd.c @@ -287,6 +287,43 @@ void cmd_kill_telescope(struct buffer *buffer) { yornp("really quit?", kill_telescope_cb, NULL); +} + +#include +#include +#include +#include +static void +do_exec_command(const char *cmd, struct tab *t) +{ + int s; + pid_t p; + + if (cmd == NULL) + return; + + endwin(); + + switch (p = fork()) { + case -1: + message("failed to fork: %s", strerror(errno)); + return; + case 0: + execl("/bin/sh", "sh", "-c", cmd, NULL); + warn("exec \"%s\" failed", cmd); + _exit(1); + } + +again: + if (waitpid(p, &s, 0) == -1) { + if (errno == EINTR) + goto again; + } + + refresh(); + clear(); + ui_schedule_redraw(); + /* rearrange_windows(); */ } void @@ -316,6 +353,13 @@ cmd_push_button(struct buffer *buffer) else buffer->line_max++; } + break; + case LINE_DOWNLOAD: + case LINE_DOWNLOAD_DONE: + minibuffer_read("Execute: ", do_exec_command, + NULL); + snprintf(ministate.buf, sizeof(ministate.buf), + "xdg-open %s", vl->parent->alt); break; default: break; blob - 18faddf332d53538a16d8ceeb2b47af6ba6be5ca blob + 93d2b08be50bfeaa5e4a9a49c0c0cddb022d752f --- sandbox.c +++ sandbox.c @@ -58,7 +58,11 @@ sandbox_ui_process(void) if (unveil(cache_path_base, "rwc") == -1) err(1, "unveil(%s)", cache_path_base); - if (pledge("stdio rpath wpath cpath unix sendfd tty", NULL) == -1) + if (unveil("/bin/sh", "rx") == -1) + err(1, "unveil(xdg-open)"); + + if (pledge("stdio rpath wpath cpath unix tty proc exec", + NULL) == -1) err(1, "pledge"); }