ctrl-l chooses urls with xurls and dmenu
This commit is contained in:
		@@ -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.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								config.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								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 } },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								st.1
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										53
									
								
								st.c
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								st.c
									
									
									
									
									
								
							@@ -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
 | 
			
		||||
iso14755(const Arg *arg)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user