Skip to content

Commit 2f235fc

Browse files
committed
MINOR: zsync: Nowadays diff command supports color output
1 parent e0c3da7 commit 2f235fc

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

zsync/zsync

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ else
4141
HAS_TTY=
4242
fi
4343

44-
if type -P colordiff >/dev/null; then
45-
HAS_COLORDIFF=1
46-
else
47-
HAS_COLORDIFF=
48-
fi
49-
5044
function exit_usage() {
5145
local status=${1:-0}
5246
[[ "$status" != "0" ]] && exec >&2
@@ -156,6 +150,16 @@ function show_diff() {
156150
local hash action mtime owner file
157151
local -a ascii_files=( )
158152

153+
local diffcolortest=$(diff --color 2>&1)
154+
if (( $? == 127 )); then
155+
error 'diff command not found'
156+
return 1
157+
elif [[ $diffcolortest != *'unrecognized option'* ]]; then
158+
local diffcmd=( diff --color=auto )
159+
else
160+
local diffcmd=( diff )
161+
fi
162+
159163
while read hash acode action mtime perm owner file ; do
160164
printf "# %s %s %s %s %s %s\n" \
161165
"$acode" "$action" \
@@ -190,12 +194,7 @@ function show_diff() {
190194
(
191195
cd "$tempdir"
192196
find old -type f -printf "%P\0" |
193-
xargs -0 -I{} diff --unidirectional-new-file -u old/{} new/{} |
194-
if [[ -n $HAS_TTY && -n $HAS_COLORDIFF ]]; then
195-
colordiff
196-
else
197-
cat
198-
fi
197+
xargs -0 -I{} "${diffcmd[@]}" --unidirectional-new-file -u old/{} new/{}
199198
)
200199
rm -rf "$tempdir"
201200
fi

0 commit comments

Comments
 (0)