Add automatic color alias for diff (copied from grep)

This commit is contained in:
Chris Adams 2025-10-25 12:54:45 -05:00
commit 14106e0b0e
5 changed files with 45 additions and 1 deletions

4
DIFF_COLORS Normal file
View file

@ -0,0 +1,4 @@
# Configuration file for the color diff utility
# 'none' shuts colorization off.
#COLOR none

9
colordiff.csh Normal file
View file

@ -0,0 +1,9 @@
# color-diff initialization
/usr/libexec/diffconf.sh -c
if ( $status == 1 ) then
exit
endif
alias diff 'diff --color=auto'

5
colordiff.sh Normal file
View file

@ -0,0 +1,5 @@
# color-diff initialization
/usr/libexec/diffconf.sh -c || return
alias diff='diff --color=auto' 2>/dev/null

11
diffconf.sh Normal file
View file

@ -0,0 +1,11 @@
#!/bin/sh
case "$1" in
-c | --interactive-color)
! diff -qsi "^COLOR.*none" /etc/DIFF_COLORS
;;
*)
echo >&2 "Invalid / no option passed, so far only -c | --interactive-color is supported."
exit 1
;;
esac

View file

@ -1,9 +1,13 @@
Summary: GNU collection of diff utilities
Name: diffutils
Version: 3.12
Release: 3%{?dist}
Release: 4%{?dist}
URL: https://www.gnu.org/software/diffutils/diffutils.html
Source: https://ftp.gnu.org/gnu/diffutils/diffutils-%{version}.tar.xz
Source2: colordiff.sh
Source3: colordiff.csh
Source4: DIFF_COLORS
Source5: diffconf.sh
# upstream fixes
# cross compile build of 3.12 diffutils fails
Patch: diffutils-3.12-cross-compiler-build-fail.patch
@ -46,6 +50,11 @@ make PR_PROGRAM=%{_bindir}/pr
%install
%make_install
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
install -pm 644 %{SOURCE2} %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
install -pm 644 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}
install -Dpm 755 %{SOURCE5} $RPM_BUILD_ROOT%{_libexecdir}/diffconf.sh
rm -f $RPM_BUILD_ROOT%{_infodir}/dir
%find_lang %{name}
@ -60,8 +69,14 @@ make check
%{_bindir}/*
%{_mandir}/*/*
%{_infodir}/diffutils.info*
%config(noreplace) %{_sysconfdir}/profile.d/colordiff.*sh
%config(noreplace) %{_sysconfdir}/DIFF_COLORS
%{_libexecdir}/diffconf.sh
%changelog
* Sat Oct 25 2025 Fedora Release Engineering <releng@fedoraproject.org> - 3.12-4
- add automatic color alias for diff (copied from grep)
* Wed Jul 23 2025 Fedora Release Engineering <releng@fedoraproject.org> - 3.12-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild