2022-04-15 14:37:35 +02:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
# Open URLs based on perl compatible regular expressions. Several commands can
|
|
|
|
# be specified with ; as separator. If the URL doesn't match anything or the
|
|
|
|
# commands are not found, use ${default_cmd}.
|
|
|
|
|
|
|
|
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
|
|
|
|
|
|
|
|
zmodload zsh/zutil
|
|
|
|
local -a o_help=()
|
|
|
|
zparseopts -D -K -- h=o_help
|
|
|
|
if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
|
2022-04-17 07:14:45 +02:00
|
|
|
local ret=$(( ${#o_help} ^ 1 ))
|
2022-04-15 14:37:35 +02:00
|
|
|
print -u $(( 1 + ${ret} )) "usage: ${0} [-h] <URL> …"
|
|
|
|
return ${ret}
|
|
|
|
fi
|
|
|
|
local -a urls=(${@})
|
|
|
|
|
2022-04-18 06:27:56 +02:00
|
|
|
autoload -U readwwwlog openwwwimg
|
2022-04-15 14:37:35 +02:00
|
|
|
zmodload zsh/pcre
|
|
|
|
|
|
|
|
local default_cmd="firefox"
|
|
|
|
local mpv="mpv --force-window=yes"
|
|
|
|
|
2022-11-03 15:20:42 +01:00
|
|
|
local -a assignments=(
|
2022-04-23 15:53:15 +02:00
|
|
|
'\.(mp4|m4v|mkv|avi|webm|flv|xvid|ogv|theora|mov|wmv)(\?.+)?$' "${mpv};vlc"
|
|
|
|
'\.(ogg|flac|opus|m4a|wav|mp3|mid|aac|wma)(\?.+)?$' "${mpv};vlc"
|
|
|
|
'^https://media\.ccc\.de/v/[^/]*$' "${mpv}"
|
2023-08-15 21:13:24 +02:00
|
|
|
'^https?://(www\.|m\.)?youtu(\.be|be\.com)/' "${mpv}"
|
2022-06-13 23:04:13 +02:00
|
|
|
'^https?://(invidious|piped|tube)\.[^/]+/watch\?v=' "${mpv}"
|
2022-05-15 12:01:06 +02:00
|
|
|
'^https://yewtu\.be/watch\?v=' "${mpv}"
|
2022-08-09 11:26:56 +02:00
|
|
|
'^https://v.redd.it/' "${mpv}"
|
2022-04-23 15:53:15 +02:00
|
|
|
'^(gemini|gopher)://' "kristall"
|
2022-11-03 15:50:34 +01:00
|
|
|
'\.(webm|png|jpe?g|gif|svg|bmp|xcf)(\?.+)?$' "openwwwimg"
|
2022-04-23 15:48:08 +02:00
|
|
|
'\.(log|txt)$' "readwwwlog"
|
2022-05-11 02:01:40 +02:00
|
|
|
'^https?://(www\.)?(dpaste|irccloud|termbin)\.com/' "readwwwlog"
|
2022-04-27 20:56:30 +02:00
|
|
|
'^https?://(www\.)?pastebin\.[^/]+/' "readwwwlog"
|
2022-04-25 10:24:07 +02:00
|
|
|
'^https?://bpa\.st/' "readwwwlog"
|
|
|
|
'^https?://sprunge\.us/' "readwwwlog"
|
2022-04-25 15:08:48 +02:00
|
|
|
'^https?://paste\.debian\.net/' "readwwwlog"
|
2022-04-26 23:43:43 +02:00
|
|
|
'^https?://paste\.centos\.org/' "readwwwlog"
|
2022-04-27 15:09:08 +02:00
|
|
|
'^https?://paste\.ee/' "readwwwlog"
|
2022-09-14 05:42:56 +02:00
|
|
|
'^https?://ix\.io/' "readwwwlog"
|
2022-11-03 15:50:34 +01:00
|
|
|
'^https?://0x0.st/' "readwwwlog"
|
2022-04-23 15:53:15 +02:00
|
|
|
'(^magnet:|\.torrent$)' "transmission-remote-gtk"
|
2022-04-15 14:37:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
local selected_cmd=${default_cmd}
|
|
|
|
for regex cmds in ${(kv)assignments}; do
|
|
|
|
if [[ ${urls[1]} -pcre-match ${regex} ]]; then
|
|
|
|
for cmd in ${(s/;/)cmds}; do
|
|
|
|
if type ${cmd%% *} >& -; then
|
|
|
|
selected_cmd=${cmd}
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
${(@s/ /)selected_cmd} ${urls}
|