From b61b58ce2c1371d6f904f108fa7feed3abfbe5c7 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 8 Apr 2026 13:18:14 +0900 Subject: * MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automated-commit-by: dots Signed-off-by: Robert Günzler --- bin/urlopen | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 bin/urlopen (limited to 'bin/urlopen') diff --git a/bin/urlopen b/bin/urlopen new file mode 100755 index 0000000..2b0479c --- /dev/null +++ b/bin/urlopen @@ -0,0 +1,89 @@ +#!/bin/bash +set -eu + +# shellcheck disable=2034 +description="url handler" + +FUZL_PROMPT=urlopen +. libfuzl.sh + +main() { + case "$#" in + 1) + fuzl_action_add "open" "" "open" + fuzl_action_add "ask" "󰮫" "ask" + fuzl_action_add "clipboard" "󰅌" "clipboard" + fuzl_action_add "primary" "󱊁" "primary" + fuzl_action_menu "$(get_text "$*")" + ;; + 2) + local action + + action=${1:?missing action} + shift + eval "urlopen_$action" "'$(get_text "$*")'" + ;; + esac +} + +# +# helpers +# + +get_text() { + local text="$*" + [ -z "$text" ] && read -r text + printf '%s' "$text" +} + +get_mimetype() { + local text=${1:?missing url} + case "$text" in + http*) printf %s 'x-scheme-handler/http' ;; + *) file -bdE --mime-type "$text" ;; + esac +} +open_default() { + local text=${1:?missing url} + local application + case "$(get_mimetype "$text")" in + x-scheme-handler/http*) application=librewolf ;; + esac + case "$text" in + *linear.app*) application=linear ;; + *) application=librewolf ;; + esac + if [ -z "$application" ]; then + gio open "$text" + else + desktop_file=$(rg -Lil -e "$application" -- /usr/share/applications/ /var/lib/flatpak/exports/share/applications/ ~/.local/share/applications/ | tail -1) + gio launch "$desktop_file" "$text" + fi +} +# +# actions +# + +urlopen_ask() { + local text=${1:?missing url} + env porta open-uri "$text" ask +} + +urlopen_open() { + local text=${1:?missing url} + open_default "$text" +} + +urlopen_clipboard() { + local text=${1:?missing url} + wl-copy -n "$text" + # fuzl_notification "copied to clipboard" "$text" +} + +urlopen_primary() { + local text=${1:?missing url} + wl-copy -np "$text" + # fuzl_notification "copied to primary" "$text" +} + +main $@ -- cgit 1.4.1