-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff-wrapper.bash
executable file
·68 lines (64 loc) · 1.55 KB
/
diff-wrapper.bash
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
#!/usr/bin/env bash
# An intelligent wrapper around different diff versions.
prog=${0##*/}
version=0.2
usage () {
echo "Usage: $prog [diff-options] [files]"
echo " $prog [git-diff-options] [git-diff-arguments]"
echo " $prog [hg-diff-options] [hg-diff-arguments]"
echo " $prog [svn-diff-options] [svn-diff-arguments]"
echo " $prog --help"
echo " $prog --version"
}
help () {
echo TOOD
}
diff_wrapper () {
if [[ $# -lt 2 && -t 0 ]]; then
echo "Error: Please specify at least two files." >&2
exit 2
elif which colordiff &>/dev/null; then
exec colordiff --nobanner "$@"
else
exec diff "$@"
fi
}
is_git_dir () {
[[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" == true ]]
}
is_mercurial_dir () {
hg -q stat 2>/dev/null
}
is_subversion_dir () {
false # TODO
}
if [[ "$1" == --help ]]; then
usage
help
exit
elif [[ "$1" == --version ]]; then
echo "$prog $version"
fi
options=()
while [[ $# -ne 0 ]]; do
case "$1" in
--) shift; break;;
-*) options+=("$1"); shift;;
*) break;;
esac
done
if [[ $# -eq 2 && -e "$1" && -e "$2" ]] || \
[[ $# -eq 3 && -e "$1" && -e "$2" && -e "$3" ]]; then
diff_wrapper "${options[@]}" "$@"
else
# We are problably in a version control repository.
if is_git_dir; then
exec git diff --irreversible-delete "${options[@]}" "$@"
elif is_mercurial_dir; then
exec hg diff "${options[@]}" "$@"
elif is_subversion_dir; then
exec svn diff "${options[@]}" "$@"
else # Fallback to normal diff.
diff_wrapper "${options[@]}" "$@"
fi
fi