commit 457800fd3ecdad35e55991739f5150f7c7cc171a
parent 8673dd9528aa07135bd5a836d1a1d1699b76bf15
Author: Santtu Lakkala <inz@inz.fi>
Date: Thu, 17 Feb 2022 18:11:35 +0200
Open url from clipboard
Based on the previous versions of the patch, but uses double-fork/execlp
instead of system() to avoid potential shell escaping issues and make
the command line building unnecessary.
Diffstat:
4 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/config.def.h b/config.def.h
@@ -202,6 +202,7 @@ static Shortcut shortcuts[] = {
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ MODKEY, XK_l, copyurl, {.i = 0} },
+ { MODKEY, XK_o, opencopied, {.v = "xdg-open"} },
};
/*
diff --git a/st.c b/st.c
@@ -816,7 +816,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
break;
default:
#ifdef __OpenBSD__
- if (pledge("stdio rpath tty proc", NULL) == -1)
+ if (pledge("stdio rpath tty proc exec", NULL) == -1)
die("pledge\n");
#endif
close(s);
diff --git a/st.h b/st.h
@@ -81,6 +81,7 @@ void die(const char *, ...);
void redraw(void);
void draw(void);
+void opencopied(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);
diff --git a/x.c b/x.c
@@ -5,6 +5,7 @@
#include <locale.h>
#include <signal.h>
#include <sys/select.h>
+#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <libgen.h>
@@ -2094,3 +2095,23 @@ run:
return 0;
}
+
+void
+opencopied(const Arg *arg)
+{
+ char * const clip = xsel.clipboard;
+ pid_t chpid;
+
+ if(!clip) {
+ fprintf(stderr, "Warning: nothing copied to clipboard\n");
+ return;
+ }
+
+ if ((chpid = fork()) == 0) {
+ if (fork() == 0)
+ execlp(arg->v, arg->v, clip, NULL);
+ exit(1);
+ }
+ if (chpid > 0)
+ waitpid(chpid, NULL, 0);
+}