-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdiffy
executable file
·55 lines (50 loc) · 848 Bytes
/
diffy
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
#!/bin/bash -e
FILE1=""
FILE2=""
ARGS="-t"
MAXWIDTH=""
# check arguments
while [ $# -gt 0 ]; do
case $1 in
-M)
MAXWIDTH=$2
shift; shift
;;
-L)
ARGS="$ARGS --left-column"
shift
;;
-t)
ARGS=$(echo "$ARGS" | sed 's/-t\b//')
shift
;;
-*)
ARGS="$ARGS $1"
shift
;;
*)
if [ -n "$FILE2" ]; then
echo "Unexpected extra argument $1"
exit 1
elif [ -n "$FILE1" ]; then
FILE2="$1"
else
FILE1="$1"
fi
shift
;;
esac
done
if [ -z "$FILE1" ] || [ -z "$FILE2" ]; then
echo "Must specify two files"
exit 1
fi
# find max length of lines in files, pad it a little
len1=$(wc -L < "$FILE1")
len2=$(wc -L < "$FILE2")
len=$(( $len1 > $len2 ? $len1 : $len2 ))
len=$(( $len*2 + 10 ))
if [ -n "$MAXWIDTH" ]; then
len=$(( $len > $MAXWIDTH ? $MAXWIDTH : $len ))
fi
diff -y --width $len $ARGS "$FILE1" "$FILE2" | less -S