dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 28c321720866059ac126f524fd1102f3ea510772
parent cfd7a7966f5ee00797b375e88fb5025be9b6ab09
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon,  3 Jun 2019 08:42:47 +0200

Improve error handling in shdl

Diffstat:
M.local/bin/shdl | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/.local/bin/shdl b/.local/bin/shdl @@ -1,4 +1,5 @@ #!/bin/sh +set -eu version=1.0 shhost="http://sci-hub.tw" @@ -55,8 +56,7 @@ shdl_fetch() { [ "$verbose" = 1 ] && echo "processing $doi" [ "$verbose" = 1 ] && echo "connecting to $shurl $prefix" pdfurl="$($prefix curl --connect-timeout 30 --silent "$shurl" | \ - grep location.href | \ - grep -o '//.*pdf' | sed 's/^/http:/')" + grep location.href | grep -o '//.*pdf' | sed 's/^/http:/')" [ "$verbose" = 1 ] && echo "fetching pdf from $pdfurl" if ! file="$($prefix curl --connect-timeout 30 \ --write-out "filename: %{filename_effective}\n" -O -L -J "$pdfurl" |\ @@ -68,8 +68,9 @@ shdl_fetch() { browser_open "$shurl" else echo "saved to $file" - if [ "$(file "$file" | cut -d' ' -f2)" = "HTML" ]; then - (echo "Error: downloaded file $file is HTML. Opening browser..." >&2) + if [ ! -f "$file" ] || [ "$(file "$file" | cut -d' ' -f2)" = "HTML" ]; then + (echo "Error: downloaded file $file is not valid. Opening browser..." >&2) + rm "$file" browser_open "$shurl" elif [ "$open" = 1 ]; then xdg-open "$file"