Skip to content

Commit b04a8c4

Browse files
committed
Guard against deleted files (fixes #7)
1 parent 9300b2f commit b04a8c4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

spaceman-diff

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,18 @@ filenameB=$(basename $5)
3636
extB=${filenameB##*.}
3737

3838
# Header row
39-
sizeA=$(expr $(ls -l $fileA | awk '{print $5}') / 1024)
40-
sizeB=$(expr $(ls -l $fileB | awk '{print $5}') / 1024)
39+
if [ -f $fileA ] ; then
40+
sizeA=$(expr $(ls -l $fileA | awk '{print $5}') / 1024)
41+
else
42+
sizeA=0
43+
fi
44+
45+
if [ -f $fileB ] ; then
46+
sizeB=$(expr $(ls -l $fileB | awk '{print $5}') / 1024)
47+
else
48+
sizeB=0
49+
fi
50+
4151
headerA="OLD: $(basename $1) ($sizeA KB)"
4252
headerB="NEW: $(basename $5) ($sizeB KB)"
4353

@@ -55,8 +65,13 @@ printf "$(yes " " | head -n$sideBySideBuffer | tr -d '\n')"
5565
printf "$(yes "" | head -n$perDiffWidth | tr -d '\n')"
5666
echo
5767

58-
outputA=$(convert $fileA jpg:- | jp2a --color --width=$perDiffWidth -)
59-
outputB=$(convert $fileB jpg:- | jp2a --color --width=$perDiffWidth -)
68+
if [ -f $fileA ] ; then
69+
outputA=$(convert $fileA jpg:- | jp2a --color --width=$perDiffWidth -)
70+
fi
71+
72+
if [ -f $fileB ] ; then
73+
outputB=$(convert $fileB jpg:- | jp2a --color --width=$perDiffWidth -)
74+
fi
6075

6176
heightA=$(echo "$outputA" | wc -l | xargs)
6277
heightB=$(echo "$outputB" | wc -l | xargs)

0 commit comments

Comments
 (0)