-
Notifications
You must be signed in to change notification settings - Fork 13
/
spaceman-diff
executable file
·99 lines (79 loc) · 1.98 KB
/
spaceman-diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
#
# spaceman-diff
# ...because you're too busy to leave the command line, dammit.
#
# Enjoy.
set -e
help()
{
cat <<EOF
This should normally be called via \`git-diff(1)\`.
USAGE:
spaceman-diff fileA shaA modeA fileB shaB modeB
EOF
}
if [ "$1" = "" ] ; then
help
exit
fi
sideBySideBuffer=4
screenWidth=$(stty size | cut -d " " -f2)
screenWidthMinusBuffer=$(expr $screenWidth - $sideBySideBuffer)
perDiffWidth=$(expr $screenWidthMinusBuffer / 2)
fileA=$2
fileB=$5
# Header row
if [ -f "$fileA" ] ; then
set +e
sizeA=$(expr $(ls -l "$fileA" | awk '{print $5}') / 1024)
geoA=$(identify -ping -format '%wx%h' "$fileA")
set -e
else
sizeA=0
geoA="0x0"
fi
if [ -f "$fileB" ] ; then
set +e
sizeB=$(expr $(ls -l "$fileB" | awk '{print $5}') / 1024)
geoB=$(identify -ping -format '%wx%h' "$fileB")
set -e
else
sizeB=0
geoB="0x0"
fi
headerA="OLD: $1 (${geoA} px @ $sizeA KB)"
headerB="NEW: $5 (${geoB} px @ $sizeB KB)"
lengthA=$(echo $headerA | wc -m | xargs)
lengthB=$(echo $headerB | wc -m | xargs)
echo
printf "$headerA"
printf "$(yes " " | head -n$(expr $perDiffWidth - $lengthA + $sideBySideBuffer + 1) | tr -d '\n')"
printf "$headerB"
echo
printf "$(yes "—" | head -n$perDiffWidth | tr -d '\n')"
printf "$(yes " " | head -n$sideBySideBuffer | tr -d '\n')"
printf "$(yes "—" | head -n$perDiffWidth | tr -d '\n')"
echo
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)
max=$(echo "$heightA\n$heightB" | sort -nr | head -n1)
for i in $(seq 1 $max)
do
A=$(echo "$outputA" | sed -n ${i}p)
B=$(echo "$outputB" | sed -n ${i}p)
if [ "$A" = "" ] ; then
A=$(yes " " | head -n$perDiffWidth | tr -d '\n')
fi
if [ "$B" = "" ] ; then
B=$(yes " " | head -n$perDiffWidth | tr -d '\n')
fi
echo "$A $B"
done
echo