mirror of
https://github.com/notwa/rc
synced 2024-06-30 19:07:11 -07:00
compute number of failures instead of keeping track
This commit is contained in:
parent
545ab4bb5d
commit
99b2991838
27
sh/oxo
27
sh/oxo
|
@ -35,31 +35,31 @@ oxo() { ### @-
|
||||||
### oxo: successfully uploaded 2 files
|
### oxo: successfully uploaded 2 files
|
||||||
### oxo: failed to upload 2 files
|
### oxo: failed to upload 2 files
|
||||||
### ```
|
### ```
|
||||||
local succs=0
|
|
||||||
local fails=0
|
|
||||||
local f= s=
|
|
||||||
|
|
||||||
local look='\033[1m%s\033[0m\n'
|
local look='\033[1m%s\033[0m\n'
|
||||||
local bad='\033[31m%s\033[0m\n'
|
local bad='\033[31m%s\033[0m\n'
|
||||||
local warn='\033[1;33m%s\033[0m\n'
|
local warn='\033[1;33m%s\033[0m\n'
|
||||||
local err='\033[1;31m%s\033[0m\n'
|
local err='\033[1;31m%s\033[0m\n'
|
||||||
|
|
||||||
|
local hits=0 total=0
|
||||||
|
local f= s=
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
curl -F'file=@-' https://0x0.st && : $((succs+=1)) || : $((fails+=1))
|
curl -F'file=@-' https://0x0.st && : $((hits+=1)) || true
|
||||||
|
total=1
|
||||||
elif [ $# -gt 255 ]; then
|
elif [ $# -gt 255 ]; then
|
||||||
printf "$err" "oxo: too many arguments (max: 255)" >&2
|
printf "$err" "oxo: too many arguments (max: 255)" >&2
|
||||||
return 255
|
return 255
|
||||||
|
else
|
||||||
|
total=$#
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for f; do
|
for f; do
|
||||||
if [ ! -e "$f" ]; then
|
if [ ! -e "$f" ]; then
|
||||||
: $((fails+=1))
|
|
||||||
printf "$bad" "oxo: no such file: $f" >&2
|
printf "$bad" "oxo: no such file: $f" >&2
|
||||||
elif [ -d "$f" ]; then
|
elif [ -d "$f" ]; then
|
||||||
: $((fails+=1))
|
|
||||||
printf "$bad" "oxo: skipping directory: $f" >&2
|
printf "$bad" "oxo: skipping directory: $f" >&2
|
||||||
elif [ ! -s "$f" ]; then
|
elif [ ! -s "$f" ]; then
|
||||||
: $((fails+=1))
|
|
||||||
printf "$bad" "oxo: skipping empty file: $f" >&2
|
printf "$bad" "oxo: skipping empty file: $f" >&2
|
||||||
else
|
else
|
||||||
local g="$f"
|
local g="$f"
|
||||||
|
@ -70,7 +70,6 @@ oxo() { ### @-
|
||||||
g=/tmp/oxo
|
g=/tmp/oxo
|
||||||
#printf "$warn" "oxo: special characters found: $f" >&2
|
#printf "$warn" "oxo: special characters found: $f" >&2
|
||||||
if ! cp -p -- "$f" "$g"; then
|
if ! cp -p -- "$f" "$g"; then
|
||||||
: $((fails+=1))
|
|
||||||
printf "$bad" "oxo: failed to copy file: $f" >&2
|
printf "$bad" "oxo: failed to copy file: $f" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
@ -79,7 +78,6 @@ oxo() { ### @-
|
||||||
local kib="$(du -k -- "$f" | cut -f1)"
|
local kib="$(du -k -- "$f" | cut -f1)"
|
||||||
|
|
||||||
if [ "$kib" -gt 524288 ]; then
|
if [ "$kib" -gt 524288 ]; then
|
||||||
: $((fails+=1))
|
|
||||||
printf "$bad" "oxo: file too large: $f" >&2
|
printf "$bad" "oxo: file too large: $f" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
@ -93,19 +91,20 @@ oxo() { ### @-
|
||||||
local r=$(( (d*-335+16384)/32768+30 ))
|
local r=$(( (d*-335+16384)/32768+30 ))
|
||||||
|
|
||||||
if ! curl -F"file=@\"$g\"" https://0x0.st; then
|
if ! curl -F"file=@\"$g\"" https://0x0.st; then
|
||||||
: $((fails+=1))
|
|
||||||
printf "$bad" "oxo: failed to upload file: $f" >&2
|
printf "$bad" "oxo: failed to upload file: $f" >&2
|
||||||
else
|
else
|
||||||
: $((succs+=1))
|
: $((hits+=1))
|
||||||
printf "$look" "oxo: expires in $r days: $f" >&2
|
printf "$look" "oxo: expires in $r days: $f" >&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $succs -gt 0 ]; then
|
local fails=$((total-hits))
|
||||||
|
|
||||||
|
if [ $hits -gt 0 ]; then
|
||||||
[ $fails -eq 0 ] && fmt="$look" || fmt="$warn"
|
[ $fails -eq 0 ] && fmt="$look" || fmt="$warn"
|
||||||
[ $succs -eq 1 ] && s= || s=s
|
[ $hits -eq 1 ] && s= || s=s
|
||||||
printf "$fmt" "oxo: successfully uploaded $succs file$s" >&2
|
printf "$fmt" "oxo: successfully uploaded $hits file$s" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $fails -gt 0 ]; then
|
if [ $fails -gt 0 ]; then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user