1
0
Fork 0

Add openwwwimg

This commit is contained in:
tastytea 2022-04-18 06:27:56 +02:00
parent 8f017a3211
commit 73e968aea0
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
3 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,7 @@
#compdef openwwwimg
_arguments '-h[short help text]' '*:url:_urls'
# Local Variables:
# mode: shell-script
# End:

View File

@ -0,0 +1,33 @@
#!/usr/bin/env zsh
# Open images from URLs by downloading them and then opening them in
# ${image_viewer}. If downloading fails, open in ${default_cmd} instead.
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
local ret=$(( ${#o_help} ^ 1 ))
print -u $(( 1 + ${ret} )) "usage: ${0} [-h] <URL> …"
return ${ret}
fi
local -a urls=(${@})
local default_cmd="firefox"
local image_viewer="viewnior"
for url in ${urls}; do
if type ${image_viewer%% *} >& -; then
local file="$(mktemp --suffix='.openwwwimg')"
curl --silent --location --output ${file} ${url}
if [[ ${?} -eq 0 ]]; then
${image_viewer} ${file}
else
${default_cmd} ${url}
fi
rm -f ${file}
else
${default_cmd} ${url}
fi
done

View File

@ -15,7 +15,7 @@ if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
fi
local -a urls=(${@})
autoload -U readwwwlog
autoload -U readwwwlog openwwwimg
zmodload zsh/pcre
local default_cmd="firefox"
@ -29,6 +29,7 @@ local -A assignments=(
'^(gemini|gopher)://' "kristall"
'\.(log|txt)$' "readwwwlog"
'^https?://(www\.)?(dpaste|pastebin|irccloud)\.com/' "readwwwlog"
'\.(webm|png|jpe?g|gif|svg|bmp|xcf)$' "openwwwimg"
)
local selected_cmd=${default_cmd}