ctrl-l chooses urls with xurls and dmenu

This commit is contained in:
Luke Smith 2018-12-13 17:23:38 -05:00
parent 6c93dd4520
commit a2b1dfe1ba
No known key found for this signature in database
GPG Key ID: 4C50B54A911F6252
5 changed files with 66 additions and 1 deletions

View File

@ -8,6 +8,8 @@ The [suckless terminal (st)](https://st.suckless.org/) with some additional feat
+ Default font is system "mono" at 16pt, meaning the font will match your system font. + Default font is system "mono" at 16pt, meaning the font will match your system font.
+ Very useful keybinds including: + Very useful keybinds including:
+ Copy is alt-c, paste is alt-v or alt-p pastes from primary selection + Copy is alt-c, paste is alt-v or alt-p pastes from primary selection
+ Alt-l feeds all urls on screen to dmenu, so they user can choose and
follow one (requires xurls and dmenu installed).
+ Zoom in/out or increase font size with Alt+Shift+k/j or u/d for larger intervals. + Zoom in/out or increase font size with Alt+Shift+k/j or u/d for larger intervals.
+ Hold alt and press either ↑/↓ or the vim keys k/j to move up/down in the terminal. + Hold alt and press either ↑/↓ or the vim keys k/j to move up/down in the terminal.
+ Shift+Mouse wheel do the same. + Shift+Mouse wheel do the same.
@ -61,7 +63,7 @@ The `alpha` value (for transparency) goes from `0` (transparent) to `255`
To be clear about the color settings: To be clear about the color settings:
- This build will use colorized colors by default and as a fallback. - This build will use gruvbox colors by default and as a fallback.
- If there are Xresources colors defined, those will take priority. - If there are Xresources colors defined, those will take priority.
- But if `wal` has run in your session, its colors will take priority. - But if `wal` has run in your session, its colors will take priority.

View File

@ -207,6 +207,9 @@ MouseKey mkeys[] = {
{ Button5, MODKEY|ShiftMask, zoom, {.f = -1} }, { Button5, MODKEY|ShiftMask, zoom, {.f = -1} },
}; };
static char *openurlcmd[] = { "/bin/sh", "-c",
"xurls | dmenu -l 10 | xargs -r xdg-open",
"externalpipe", NULL };
static Shortcut shortcuts[] = { static Shortcut shortcuts[] = {
/* mask keysym function argument */ /* mask keysym function argument */
@ -239,6 +242,7 @@ static Shortcut shortcuts[] = {
{ MODKEY|ShiftMask, XK_J, zoom, {.f = -1} }, { MODKEY|ShiftMask, XK_J, zoom, {.f = -1} },
{ MODKEY|ShiftMask, XK_U, zoom, {.f = +2} }, { MODKEY|ShiftMask, XK_U, zoom, {.f = +2} },
{ MODKEY|ShiftMask, XK_D, zoom, {.f = -2} }, { MODKEY|ShiftMask, XK_D, zoom, {.f = -2} },
{ MODKEY, XK_l, externalpipe, { .v = openurlcmd } },
}; };
/* /*

5
st.1
View File

@ -146,6 +146,11 @@ Copy to clipboard.
.B Alt-p .B Alt-p
Paste/input primary selection. Paste/input primary selection.
.TP .TP
.B Alt-l
Show dmenu menu of all URLs on screen and choose one to open.
.I Note:
Requires xurls installed.
.TP
.B Break .B Break
Send a break in the serial line. Send a break in the serial line.
Break key is obtained in PC keyboards Break key is obtained in PC keyboards

53
st.c
View File

@ -2029,6 +2029,59 @@ tprinter(char *s, size_t len)
} }
} }
void
externalpipe(const Arg *arg)
{
int to[2];
char buf[UTF_SIZ];
void (*oldsigpipe)(int);
Glyph *bp, *end;
int lastpos, n, newline;
if (pipe(to) == -1)
return;
switch (fork()) {
case -1:
close(to[0]);
close(to[1]);
return;
case 0:
dup2(to[0], STDIN_FILENO);
close(to[0]);
close(to[1]);
execvp(((char **)arg->v)[0], (char **)arg->v);
fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
perror("failed");
exit(0);
}
close(to[0]);
/* ignore sigpipe for now, in case child exists early */
oldsigpipe = signal(SIGPIPE, SIG_IGN);
newline = 0;
for (n = 0; n < term.row; n++) {
bp = term.line[n];
lastpos = MIN(tlinelen(n) + 1, term.col) - 1;
if (lastpos < 0)
break;
end = &bp[lastpos + 1];
for (; bp < end; ++bp)
if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
break;
if ((newline = term.line[n][lastpos].mode & ATTR_WRAP))
continue;
if (xwrite(to[1], "\n", 1) < 0)
break;
newline = 0;
}
if (newline)
(void)xwrite(to[1], "\n", 1);
close(to[1]);
/* restore */
signal(SIGPIPE, oldsigpipe);
}
void void
iso14755(const Arg *arg) iso14755(const Arg *arg)
{ {

1
st.h
View File

@ -92,6 +92,7 @@ void die(const char *, ...);
void redraw(void); void redraw(void);
void draw(void); void draw(void);
void externalpipe(const Arg *);
void iso14755(const Arg *); void iso14755(const Arg *);
void printscreen(const Arg *); void printscreen(const Arg *);
void printsel(const Arg *); void printsel(const Arg *);