New approach to url opening.

This commit is contained in:
Bartek Stalewski 2022-03-06 15:16:16 +01:00
parent 5957ed5673
commit a85fe068bd
4 changed files with 7 additions and 27 deletions

View File

@ -47,7 +47,7 @@ static const Rule rules[] = {
*/
/* class instance title tags mask isfloating isterminal noswallow monitor */
{ NULL, NULL, "st", 0, 0, 1, 0, -1 },
{ "Firefox", NULL, NULL, 2, 0, 0, 0, -1 },
{ "Firefox", NULL, NULL, 2, 0, 0, 1, -1 },
{ "Ferdi", NULL, NULL, 1 << 2, 0, 0, 0, -1 },
{ "Slack", NULL, NULL, 1 << 7, 0, 0, 0, -1 },
{ NULL, "mutt", NULL, 1 << 3, 0, 1, 1, -1 },
@ -101,8 +101,9 @@ static Key keys[] = {
TAGKEYS( XK_9, 8)
TAGKEYS( XK_0, 9)
/* apps n'shit */
{ MODKEY, XK_Return, spawn, {.v = termcmd } },
{ SHTKEY, XK_Return, spawn, SHCMD("st -n f_work") },
//{ MODKEY, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_Return, spawn, SHCMD("BROWSER=firefox st") },
{ SHTKEY, XK_Return, spawn, SHCMD("BROWSER=workfx st -n f_work") },
{ MODKEY, XK_space, spawn, SHCMD("dmenu_run -c -i -l 20") },
{ MODKEY, XK_i, spawn, SHCMD("scrot -f -s 'scrot_%Y-%m-%d_%H-%M-%S_%s.png'") },
{ SHTKEY, XK_i, spawn, SHCMD("scrot 'scrot_%Y-%m-%d_%H-%M-%S_%s.png'") },

View File

@ -44,9 +44,7 @@ dist: clean
install: st
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f st $(DESTDIR)$(PREFIX)/bin
cp -f st-url $(DESTDIR)$(PREFIX)/bin
chmod 755 $(DESTDIR)$(PREFIX)/bin/st
chmod 755 $(DESTDIR)$(PREFIX)/bin/st-url
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
sed "s/VERSION/$(VERSION)/g" < st.1 > $(DESTDIR)$(MANPREFIX)/man1/st.1
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1

View File

@ -191,8 +191,9 @@ static MouseShortcut mshortcuts[] = {
#define MODKEY ControlMask
#define SHTKEY (ControlMask|ShiftMask)
static char *openurlcmd[] = { "/bin/sh", "-c", "st-url -o", "externalpipe", NULL };
static char *copyurlcmd[] = { "/bin/sh", "-c", "st-url -c", "externalpipe", NULL };
//static char *openurlcmd[] = { "/bin/sh", "-c", "st-url -o", "externalpipe", NULL };
static char *openurlcmd[] = {"/bin/sh", "-c", "xurls | dmenu -c -l 20 -i | xargs -r $BROWSER",
"externalpipe", NULL};
static Shortcut shortcuts[] = {
/* mask keysym function argument */
@ -203,7 +204,6 @@ static Shortcut shortcuts[] = {
{ SHTKEY, XK_V, clippaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ MODKEY, XK_o, externalpipe, {.v = openurlcmd } },
{ SHTKEY, XK_O, externalpipe, {.v = copyurlcmd } },
{ MODKEY, XK_k, kscrollup, {.i = 1} },
{ MODKEY, XK_j, kscrolldown, {.i = 1} },
};

View File

@ -1,19 +0,0 @@
#!/bin/sh
urlregex="(((http|https|gopher|gemini|ftp|ftps|git)://|www\\.)[a-zA-Z0-9.]*[:]?[a-zA-Z0-9.,/:@$&%?$\#=_~-]*)|((magnet:\\?xt=urn:btih:)[a-zA-Z0-9]*)"
urls="$(sed 's/.*│//g' | tr -d '\n' | # First remove linebreaks and mutt sidebars:
grep -aEo "$urlregex" | # grep only urls as defined above.
uniq | # Ignore neighboring duplicates.
sed "s/\(\.\|,\|;\|\!\\|\?\)$//;
s/^www./http:\/\/www\./")" # xdg-open will not detect url without http
[ -z "$urls" ] && exit 1
while getopts "hoc" o; do case "${o}" in
h) printf "Optional arguments for custom use:\\n -c: copy\\n -o: xdg-open\\n -h: Show this message\\n" && exit 1 ;;
o) chosen="$(echo "$urls" | dmenu -c -l 20 -i)"
setsid xdg-open "$chosen" >/dev/null 2>&1 & ;;
c) echo "$urls" | dmenu -c -l 20 -i| tr -d '\n' | xsel -l /dev/null ;;
*) printf "Invalid option: -%s\\n" "$OPTARG" && exit 1 ;;
esac done