From baa9fa076a4e334e04532b218a925b0a8e367a8c Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Wed, 15 Apr 2020 16:43:14 -0400 Subject: [PATCH] following links now separate script this avoids the effects of swallow in dwm it also will not produce dmenu without found urls --- Makefile | 3 +++ config.h | 4 +--- st-urlhandler | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100755 st-urlhandler diff --git a/Makefile b/Makefile index 3442e32..39f757f 100644 --- a/Makefile +++ b/Makefile @@ -44,8 +44,10 @@ install: st mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f st $(DESTDIR)$(PREFIX)/bin cp -f st-copyout $(DESTDIR)$(PREFIX)/bin + cp -f st-urlhandler $(DESTDIR)$(PREFIX)/bin chmod 755 $(DESTDIR)$(PREFIX)/bin/st chmod 755 $(DESTDIR)$(PREFIX)/bin/st-copyout + chmod 755 $(DESTDIR)$(PREFIX)/bin/st-urlhandler mkdir -p $(DESTDIR)$(MANPREFIX)/man1 sed "s/VERSION/$(VERSION)/g" < st.1 > $(DESTDIR)$(MANPREFIX)/man1/st.1 chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1 @@ -55,6 +57,7 @@ install: st uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/st rm -f $(DESTDIR)$(PREFIX)/bin/st-copyout + rm -f $(DESTDIR)$(PREFIX)/bin/st-urlhandler rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1 .PHONY: all options clean dist install uninstall diff --git a/config.h b/config.h index 0c2115b..1d3a8a4 100644 --- a/config.h +++ b/config.h @@ -221,9 +221,7 @@ MouseKey mkeys[] = { { Button5, TERMMOD, zoom, {.f = -1} }, }; -static char *openurlcmd[] = { "/bin/sh", "-c", - "sed 's/.*│//g' | tr -d '\n' | grep -aEo '(((http|https)://|www\\.)[a-zA-Z0-9.]*[:]?[a-zA-Z0-9./@&%?$#=_-]*)|((magnet:\\?xt=urn:btih:)[a-zA-Z0-9]*)'| uniq | sed 's/^www./http:\\/\\/www\\./g' | dmenu -w $(xdotool getactivewindow) -i -p 'Follow which url?' -l 10 | xargs -r xdg-open", - "externalpipe", NULL }; +static char *openurlcmd[] = { "/bin/sh", "-c", "st-urlhandler", "externalpipe", NULL }; static char *copyurlcmd[] = { "/bin/sh", "-c", "sed 's/.*│//g' | tr -d '\n' | grep -aEo '(((http|https)://|www\\.)[a-zA-Z0-9.]*[:]?[a-zA-Z0-9./@&%?$#=_-]*)|((magnet:\\?xt=urn:btih:)[a-zA-Z0-9]*)' | uniq | sed 's/^www./http:\\/\\/www\\./g' | dmenu -w $(xdotool getactivewindow) -i -p 'Copy which url?' -l 10 | tr -d '\n' | xclip -selection clipboard", diff --git a/st-urlhandler b/st-urlhandler new file mode 100755 index 0000000..a68c46c --- /dev/null +++ b/st-urlhandler @@ -0,0 +1,15 @@ +#!/bin/sh + +urlregex="(((http|https)://|www\\.)[a-zA-Z0-9.]*[:]?[a-zA-Z0-9./@&%?$#=_-]*)|((magnet:\\?xt=urn:btih:)[a-zA-Z0-9]*)" + +# First remove linebreaks and mutt sidebars: +urls="$(sed 's/.*│//g' | tr -d '\n' | + grep -aEo "$urlregex" | # grep only urls as defined above. + uniq | # Ignore neighboring duplicates. + sed 's/^www./http:\/\/www\./g')" + +[ -z "$urls" ] && exit + +chosen="$(echo "$urls" | dmenu -w "$(xdotool getactivewindow)" -i -p 'Follow which url?' -l 10)" + +setsid xdg-open "$chosen" >/dev/null 2>&1 &