-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquickdiff
executable file
·47 lines (39 loc) · 1.42 KB
/
quickdiff
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
#!/usr/bin/env python
# vi: syntax=python
# visualize the diff between two bits of text:
# paste in first bit of text
# hit Control-D
# paste in second bit of text
# see result in vimdiff
# Dependencies:
# needs my waterworks library:
# https://github.com/dmcc/waterworks
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
from vimdiff import vimdiff
import optparse
import sys
parser = optparse.OptionParser()
parser.add_option('-w', '--split-by-whitespace', action='store_true',
help='Convert all whitespace to newlines')
parser.add_option('-s', '--split-by-sentences', action='store_true',
help='Convert sentence breaks (not very general: ". ") to '
'newlines')
parser.add_option('-d', '--split-by-delimiter',
help='Split into lines by a delimter.', metavar='DELIMITER')
opts, args = parser.parse_args()
# TODO could be generalized to K bits of text
def split(text):
if opts.split_by_whitespace:
text = '\n'.join(text.split())
elif opts.split_by_sentences:
text = '\n'.join(text.split('. '))
elif opts.split_by_delimiter:
text = '\n'.join(text.split(opts.split_by_delimiter))
return text
text1 = split(sys.stdin.read().strip())
print("Read text 1 (%s chars)" % len(text1))
text2 = split(sys.stdin.read().strip())
print("Read text 2 (%s chars)" % len(text2))
vimdiff(text1, text2)