diff --git a/.config/zsh/functions/readwwwlog b/.config/zsh/functions/readwwwlog index a411742..171933a 100755 --- a/.config/zsh/functions/readwwwlog +++ b/.config/zsh/functions/readwwwlog @@ -4,6 +4,9 @@ setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL +# Remove temporary files on exit +trap "rm -r ${$(mktemp --dry-run --suffix='.end')/.*.end/.*.readwwwlog}" EXIT + zmodload zsh/zutil local -a o_help=() zparseopts -D -K -- h=o_help @@ -40,7 +43,6 @@ for url in ${urls}; do 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 @@ -50,14 +52,12 @@ for url in ${urls}; do if [[ ${headers[(I)*text/plain*]} -ne 0 ]] || \ [[ ${headers[(I)*HTTP/1.1 405*]} -ne 0 ]]; then # No HEAD allowed [[ ${url} =~ 'dpaste\.com' ]] && sleep 1 + local file="$(mktemp --suffix='.readwwwlog')" 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 + local dir="$(mktemp --directory --suffix='.readwwwlog')" + local file=${dir}/archive.zip curl --silent --location --output ${file} ${url} unzip -qd ${dir} ${file} @@ -66,7 +66,6 @@ for url in ${urls}; do ${cmd} ${txt} fi done - rm -r ${dir} else ${default_cmd} ${url} fi