st

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a2b1dfe1ba2309fe6ce615ed02fc6e36efed99e9
parent 6c93dd4520fc74d0dca7d023b95e8dc946cda214
Author: Luke Smith <luke@lukesmith.xyz>
Date:   Thu, 13 Dec 2018 17:23:38 -0500

ctrl-l chooses urls with xurls and dmenu

Diffstat:
MREADME.md | 4+++-
Mconfig.h | 4++++
Mst.1 | 5+++++
Mst.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Mst.h | 1+
5 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md @@ -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. + Very useful keybinds including: + 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. + Hold alt and press either ↑/↓ or the vim keys k/j to move up/down in the terminal. + 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: -- 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. - But if `wal` has run in your session, its colors will take priority. diff --git a/config.h b/config.h @@ -207,6 +207,9 @@ MouseKey mkeys[] = { { 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[] = { /* mask keysym function argument */ @@ -239,6 +242,7 @@ static Shortcut shortcuts[] = { { MODKEY|ShiftMask, XK_J, zoom, {.f = -1} }, { MODKEY|ShiftMask, XK_U, zoom, {.f = +2} }, { MODKEY|ShiftMask, XK_D, zoom, {.f = -2} }, + { MODKEY, XK_l, externalpipe, { .v = openurlcmd } }, }; /* diff --git a/st.1 b/st.1 @@ -146,6 +146,11 @@ Copy to clipboard. .B Alt-p Paste/input primary selection. .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 Send a break in the serial line. Break key is obtained in PC keyboards diff --git a/st.c b/st.c @@ -2030,6 +2030,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 iso14755(const Arg *arg) { FILE *p; diff --git a/st.h b/st.h @@ -92,6 +92,7 @@ void die(const char *, ...); void redraw(void); void draw(void); +void externalpipe(const Arg *); void iso14755(const Arg *); void printscreen(const Arg *); void printsel(const Arg *);