Add openwwwimg
This commit is contained in:
parent
8f017a3211
commit
73e968aea0
7
.config/zsh/completions/_openwwwimg
Normal file
7
.config/zsh/completions/_openwwwimg
Normal file
|
@ -0,0 +1,7 @@
|
|||
#compdef openwwwimg
|
||||
|
||||
_arguments '-h[short help text]' '*:url:_urls'
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# End:
|
33
.config/zsh/functions/openwwwimg
Executable file
33
.config/zsh/functions/openwwwimg
Executable 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
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue
Block a user