From 7b35fb38c959eb49e59e68c253a02a5d17ce9db9 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 25 Apr 2022 10:24:07 +0200 Subject: [PATCH] Add support for bpa.st and spunge.us to readwwwlog --- .config/zsh/functions/readwwwlog | 41 ++++++++++++++++++++++++-------- .local/bin/urlhandler | 2 ++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/.config/zsh/functions/readwwwlog b/.config/zsh/functions/readwwwlog index d6e7e29..dc3b0ab 100755 --- a/.config/zsh/functions/readwwwlog +++ b/.config/zsh/functions/readwwwlog @@ -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 diff --git a/.local/bin/urlhandler b/.local/bin/urlhandler index 6401875..2ad0b49 100755 --- a/.local/bin/urlhandler +++ b/.local/bin/urlhandler @@ -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" )