From 7343a15f123c78d7c29ff7a189798de689869026 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Fri, 7 Mar 2025 00:41:38 -0300 Subject: Initial commit. --- terminal/.local/bin/urlhandler | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 terminal/.local/bin/urlhandler (limited to 'terminal/.local/bin') 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 -- cgit v1.2.3