-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
jwdiff
executable file
·61 lines (52 loc) · 1.21 KB
/
jwdiff
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
#!/bin/bash
##
## jwdiff: Display word differences between Japanese text files
## Copyright (c) 2013 SATOH Fumiyasu @ OSS Technology Corp., Japan
## <https://github.com/fumiyas/home-commands/blob/master/jwdiff>
## <https://fumiyas.github.io/>
## <http://www.osstech.co.jp/>
##
## License: GNU General Public License version 3
##
set -u
pdie() {
echo "$0: ERROR: $1"
exit ${2-1}
}
wakati() {
expand ${1+"$1"} \
|mecab \
--node-format '%M\t' \
--eos-format '\n' \
;
}
usage="\
Usage:
${0##*/} [OPTION] FILE1 FILE2
${0##*/} -d [OPTION]
Options:
See wdiff(1) manpage
"
if [[ ${1-} = -d ]] || [[ ${1-} = --diff-input ]]; then
wakati |wdiff "$@" |sed 's/ //g'
else
if [[ $# -lt 2 ]]; then
echo "$usage" 1>&2
exit 1
fi
args=("$@")
args_last=$((${#args[@]} - 1))
file2="${args[$args_last]}";
unset args[$args_last]
let args_last--
file1="${args[$args_last]}";
unset args[$args_last]
[[ -f $file1 ]] || [[ -L $file1 ]] || pdie "No such file: $file1"
[[ -f $file2 ]] || [[ -L $file2 ]] || pdie "No such file: $file2"
wdiff \
${args+"${args[@]}"} \
<(wakati "$file1") \
<(wakati "$file2") \
|sed 's/ //g' \
;
fi