Skip to content

Commit

Permalink
Guard against deleted files (fixes #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
holman committed Dec 16, 2015
1 parent 9300b2f commit b04a8c4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions spaceman-diff
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ filenameB=$(basename $5)
extB=${filenameB##*.}

# Header row
sizeA=$(expr $(ls -l $fileA | awk '{print $5}') / 1024)
sizeB=$(expr $(ls -l $fileB | awk '{print $5}') / 1024)
if [ -f $fileA ] ; then
sizeA=$(expr $(ls -l $fileA | awk '{print $5}') / 1024)
else
sizeA=0
fi

if [ -f $fileB ] ; then
sizeB=$(expr $(ls -l $fileB | awk '{print $5}') / 1024)
else
sizeB=0
fi

headerA="OLD: $(basename $1) ($sizeA KB)"
headerB="NEW: $(basename $5) ($sizeB KB)"

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

outputA=$(convert $fileA jpg:- | jp2a --color --width=$perDiffWidth -)
outputB=$(convert $fileB jpg:- | jp2a --color --width=$perDiffWidth -)
if [ -f $fileA ] ; then
outputA=$(convert $fileA jpg:- | jp2a --color --width=$perDiffWidth -)
fi

if [ -f $fileB ] ; then
outputB=$(convert $fileB jpg:- | jp2a --color --width=$perDiffWidth -)
fi

heightA=$(echo "$outputA" | wc -l | xargs)
heightB=$(echo "$outputB" | wc -l | xargs)
Expand Down

0 comments on commit b04a8c4

Please sign in to comment.