summaryrefslogtreecommitdiff
path: root/terminal/.local/bin/urlhandler
diff options
context:
space:
mode:
Diffstat (limited to 'terminal/.local/bin/urlhandler')
-rwxr-xr-xterminal/.local/bin/urlhandler25
1 files changed, 25 insertions, 0 deletions
diff --git a/terminal/.local/bin/urlhandler b/terminal/.local/bin/urlhandler
new file mode 100755
index 0000000..021c487
--- /dev/null
+++ b/terminal/.local/bin/urlhandler
@@ -0,0 +1,25 @@
+#!/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
+
+if [ $(echo "$urls" | wc -l) = "1" ]; then
+ chosen_url="$urls"
+else
+ chosen_url="$(echo "$urls" | rofi -dmenu -i -p "󰌹" -l 10)"
+fi
+
+case "$chosen_url" in
+ http://*suckless.org*|https://*suckless.org*) command="surf" ;;
+ https://*.reliant.io*|https://acumera.*) command="/usr/bin/librewolf -P work" ;;
+ *) command="xdg-open" ;;
+esac
+
+setsid $command "$chosen_url" >/dev/null 2>&1