-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiffCousin
More file actions
executable file
·44 lines (38 loc) · 1.21 KB
/
diffCousin
File metadata and controls
executable file
·44 lines (38 loc) · 1.21 KB
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
#!/bin/sh
if [[ "$1" == "-h" || ! "$3" ]]; then
cat <<EOF
Usage:
diffCousin [path] [otherDir]
Find a corresponding file in the same relative position in another dir, and diff.
For example, say you have ~/myStuff/code/foo/bar/spam/eggs/stuff.py, and also a
backup or other near-copy of myStuff/ under ~/spares/myStuff2.
To diff the versions of stuff.py:
diffCousin ~/myStuff ~/spares/myStuff2 code/foo/bar/spam/eggs/stuff.py
This will check under the directories given by the first two arguments, for a file
at the relative path given by the third argument. Assuming they both exist, they'll
be handed to \$DIFFER (current set to '$DIFFER').
Note: The third argument usually won't autocomplete while typing the command.
EOF
exit
fi
if ! [ -d "$1" ]; then
echo "First directory not found: '$1'."
exit
fi
if ! [ -d "$2" ]; then
echo "First directory not found: '$2'."
exit
fi
file1="$1/$3"
if ! [ -e "$file1" ]; then
echo "File not found under first directory: '$file1'."
exit
fi
file2="$2/$3"
if ! [ -e "$file2" ]; then
echo "File not found under second directory: '$file2'."
exit
fi
[ $DIFFER ] || DIFFER="diff"
echo "Running $DIFFER \"$file1\" \"$file2\"."
$differ "$file1" "$file2"