-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkdiff.sh
executable file
·71 lines (67 loc) · 1.69 KB
/
kdiff.sh
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
#! /bin/bash
#
# kdiff.sh: Invokes kdiff3 over the files making sure unix paths resolved to windows
# if under Cygwin.
#
#
# Uncomment following line(s) for tracing:
# - xtrace shows arg expansion (and often is sufficient)
# - verbose shows source commands as is (but usually is superfluous w/ xtrace)
#
## set -o xtrace
## set -o verbose
# Parse command-line options
#
kdiff="kdiff3"
#
moreoptions=0; case "$1" in -*) moreoptions=1 ;; esac
show_usage=0
while [ "$moreoptions" == "1" ]; do
if [ "$1" == "--trace" ]; then
set -o xtrace;
elif [ "$1" == "--cmd" ]; then
kdiff="$2"
shift
elif [ "$1" == "--help" ]; then
show_usage=1
else
echo "ERROR: Unknown option: $1";
exit;
fi
shift 1;
moreoptions=0; case "$1" in -*) moreoptions=1 ;; esac
done
#
# Show usage statement if need be
#
if [[ ("$2" == "") && ("$show_usage" == "0") ]]; then
echo ""
echo "Error: missing filename"
show_usage=1
fi
if [ "$show_usage" == "1" ]; then
script=$(basename "$0")
echo ""
echo "Usage: $script [options] filename1 filename2"
echo " options: [--trace] [--help] [--cmd diff-path]"
echo ""
echo "Example:"
echo " $0 diff.sh do_diff.sh"
echo ""
exit
fi
file1="$1"
file2="$2"
if [ "$OSTYPE" == "cygwin" ]; then
file1=$(cygpath -w "$file1")
file2=$(cygpath -w "$file2")
kdiff="cygstart $kdiff"
fi
# Make sure file2 exists, using file1 pattern unless absolute-ish
base1="$(basename "$file1")"
## OLD: if [[ (-d "$file2") && (! "$file1" =~ ^[\/\.].*) && (! -e "$file2/$base1") ]]; then
if [[ (-d "$file2") && (! -e "$file2/$base1") ]]; then
file2="$file2/$file1"
fi
# Invoke kdiff
$kdiff "$file1" "$file2" 2>| "$TMP/kdiff-$$.log" &