1
0
Fork 0

Add support for bpa.st and spunge.us to readwwwlog

This commit is contained in:
tastytea 2022-04-25 10:24:07 +02:00
parent 23ad6625ba
commit 7b35fb38c9
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 33 additions and 10 deletions

View File

@ -25,25 +25,46 @@ for url in ${urls}; do
elif [[ ${url} =~ 'irccloud\.com' && ! ${url} =~ '/raw/' ]]; then
local id=${${(@s:/:)url}[4]}
url="https://www.irccloud.com/pastebin/raw/${id}"
elif [[ ${url} =~ 'bpa\.st' && ! ${url} =~ '/download-archive/' ]]; then
local id=${url##*/}
url="https://bpa.st/download-archive/${id}"
fi
if [[ ${TERMINAL} =~ "alacritty|xfce4-terminal" ]]; then
termopts="--title=${url}"
fi
if curl --silent --location --head ${url} | grep -q 'text/plain'; then
sleep 1 # dpaste.com workaround
local file="$(mktemp --suffix='.readwwwlog')"
curl --silent --location --output ${file} ${url}
local curl="$(curl --silent --location --head ${url})"
local -a headers=(${(ps:\r\n:)curl})
local file="$(mktemp --suffix='.readwwwlog')"
local -a cmd=(less +1 --LINE-NUMBERS --ignore-case \
--pattern='(error|fail):')
if [[ -o NO_INTERACTIVE ]]; then
cmd=(${TERMINAL} ${termopts} -e ${cmd})
fi
local -a cmd=(less +1 --LINE-NUMBERS --ignore-case \
--pattern='(error|fail):' ${file})
if [[ -o NO_INTERACTIVE ]]; then
cmd=(${TERMINAL} ${termopts} -e ${cmd})
fi
${cmd}
if [[ ${headers[(I)*text/plain]} -ne 0 ]] || \
[[ ${headers[(I)*HTTP/1.1 405*]} -ne 0 ]]; then # No HEAD allowed
sleep 1 # dpaste.com workaround
curl --silent --location --output ${file} ${url}
${cmd} ${file}
rm ${file}
elif [[ ${headers[(I)*application/zip]} -ne 0 ]]; then
rm ${file}
local dir=${file}
mkdir ${dir}
file=${dir}/archive.zip
curl --silent --location --output ${file} ${url}
unzip -qd ${dir} ${file}
for txt in ${dir}/*; do
if [[ ${txt} != "${dir}/archive.zip" ]]; then
${cmd} ${txt}
fi
done
rm -r ${dir}
else
${default_cmd} ${url}
fi

View File

@ -29,6 +29,8 @@ local -A assignments=(
'^(gemini|gopher)://' "kristall"
'\.(log|txt)$' "readwwwlog"
'^https?://(www\.)?(dpaste|pastebin|irccloud)\.com/' "readwwwlog"
'^https?://bpa\.st/' "readwwwlog"
'^https?://sprunge\.us/' "readwwwlog"
'\.(webm|png|jpe?g|gif|svg|bmp|xcf)(\?.+)?$' "openwwwimg"
'(^magnet:|\.torrent$)' "transmission-remote-gtk"
)