st-open-selected-0.9.2.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
st-open-selected-0.9.2.diff (2090B)
---
1 diff --git a/config.def.h b/config.def.h
2 index 2cd740a..d362d6b 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -176,6 +176,7 @@ static uint forcemousemod = ShiftMask;
6 */
7 static MouseShortcut mshortcuts[] = {
8 /* mask button function argument release */
9 + { ControlMask, Button2, selopen, {.i = 0}, 1 },
10 { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
11 { ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} },
12 { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
13 diff --git a/st.c b/st.c
14 index 2e3800e..f55facb 100644
15 --- a/st.c
16 +++ b/st.c
17 @@ -1903,6 +1903,16 @@ strhandle(void)
18 if (narg > 1)
19 xsettitle(strescseq.args[1]);
20 return;
21 + case 7:
22 + if (strstr(strescseq.args[1], "file://") != strescseq.args[1]) {
23 + fprintf(stderr, "erresc: dir %s must have prefix 'file://'\n",
24 + strescseq.args[1]);
25 + return;
26 + }
27 + if (chdir(strescseq.args[1] + 7) != 0) /* +7 to remove prefix */
28 + fprintf(stderr, "erresc: invalid directory %s\n",
29 + strescseq.args[1]);
30 + return;
31 case 52:
32 if (narg > 2 && allowwindowops) {
33 dec = base64dec(strescseq.args[2]);
34 diff --git a/x.c b/x.c
35 index d73152b..e44d61c 100644
36 --- a/x.c
37 +++ b/x.c
38 @@ -5,6 +5,7 @@
39 #include <locale.h>
40 #include <signal.h>
41 #include <sys/select.h>
42 +#include <sys/wait.h>
43 #include <time.h>
44 #include <unistd.h>
45 #include <libgen.h>
46 @@ -55,6 +56,7 @@ static void clipcopy(const Arg *);
47 static void clippaste(const Arg *);
48 static void numlock(const Arg *);
49 static void selpaste(const Arg *);
50 +static void selopen(const Arg *);
51 static void zoom(const Arg *);
52 static void zoomabs(const Arg *);
53 static void zoomreset(const Arg *);
54 @@ -286,6 +288,20 @@ selpaste(const Arg *dummy)
55 xw.win, CurrentTime);
56 }
57
58 +void
59 +selopen(const Arg *dummy)
60 +{
61 + pid_t chpid;
62 +
63 + if ((chpid = fork()) == 0) {
64 + if (fork() == 0)
65 + execlp("xdg-open", "xdg-open", getsel(), NULL);
66 + exit(1);
67 + }
68 + if (chpid > 0)
69 + waitpid(chpid, NULL, 0);
70 +}
71 +
72 void
73 numlock(const Arg *dummy)
74 {