add key to insert text selected with dmenu as terminal input
This commit is contained in:
@@ -20,6 +20,10 @@ static char *externalcopycmd[] = { "/bin/sh", "-c",
|
||||
"sed 's/[ \t][ \t]*/\\n/g' | tac | awk '!x[$0]++' | dmenu -l 10 -w $WINDOWID | tr --delete '\\n' | vis-clipboard --copy",
|
||||
NULL};
|
||||
|
||||
static char *externalinsertcmd[] = { "/bin/sh", "-c",
|
||||
"sed 's/[ \t][ \t]*/\\n/g' | tac | awk '!x[$0]++' | dmenu -l 10 -w $WINDOWID | tr --delete '\\n'",
|
||||
NULL};
|
||||
|
||||
/*
|
||||
* What program is execed by st depends of these precedence rules:
|
||||
* 1: program passed with -e
|
||||
@@ -213,6 +217,7 @@ static Shortcut shortcuts[] = {
|
||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||
{ TERMMOD, XK_E, externalpipe, { .v = externaleditcmd } },
|
||||
{ TERMMOD, XK_K, externalpipe, { .v = externalcopycmd } },
|
||||
{ TERMMOD, XK_I, externalpipettycopy, { .v = externalinsertcmd } },
|
||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
|
||||
|
||||
46
st.c
46
st.c
@@ -2117,9 +2117,9 @@ strparse(void)
|
||||
}
|
||||
|
||||
void
|
||||
externalpipe(const Arg *arg)
|
||||
externalpipeinout(const Arg *arg, void (*processout)(int fildes))
|
||||
{
|
||||
int to[2];
|
||||
int to[2], from[2];
|
||||
char buf[UTF_SIZ];
|
||||
void (*oldsigpipe)(int);
|
||||
Glyph *bp, *end;
|
||||
@@ -2127,16 +2127,27 @@ externalpipe(const Arg *arg)
|
||||
|
||||
if (pipe(to) == -1)
|
||||
return;
|
||||
if (processout != NULL && pipe(from) == -1)
|
||||
return;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
close(to[0]);
|
||||
close(to[1]);
|
||||
if (processout != NULL) {
|
||||
close(from[0]);
|
||||
close(from[1]);
|
||||
}
|
||||
return;
|
||||
case 0:
|
||||
dup2(to[0], STDIN_FILENO);
|
||||
close(to[0]);
|
||||
close(to[1]);
|
||||
if (processout != NULL) {
|
||||
dup2(from[1], STDOUT_FILENO);
|
||||
close(from[0]);
|
||||
close(from[1]);
|
||||
}
|
||||
execvp(((char **)arg->v)[0], (char **)arg->v);
|
||||
fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
|
||||
perror("failed");
|
||||
@@ -2144,6 +2155,8 @@ externalpipe(const Arg *arg)
|
||||
}
|
||||
|
||||
close(to[0]);
|
||||
if (processout != NULL)
|
||||
close(from[1]);
|
||||
/* ignore sigpipe for now, in case child exists early */
|
||||
oldsigpipe = signal(SIGPIPE, SIG_IGN);
|
||||
newline = 0;
|
||||
@@ -2165,10 +2178,39 @@ externalpipe(const Arg *arg)
|
||||
if (newline)
|
||||
(void)xwrite(to[1], "\n", 1);
|
||||
close(to[1]);
|
||||
if (processout != NULL) {
|
||||
processout(from[0]);
|
||||
close(from[0]);
|
||||
}
|
||||
/* restore */
|
||||
signal(SIGPIPE, oldsigpipe);
|
||||
}
|
||||
|
||||
void
|
||||
externalpipe(const Arg *arg)
|
||||
{
|
||||
externalpipeinout(arg, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
ttycopy(int fildes)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
len = read(fildes, buf, sizeof(buf));
|
||||
if (len > 0 && len < sizeof(buf)) {
|
||||
buf[len] = '\0';
|
||||
ttywrite(buf, len, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
externalpipettycopy(const Arg *arg)
|
||||
{
|
||||
externalpipeinout(arg, ttycopy);
|
||||
}
|
||||
|
||||
void
|
||||
strdump(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user