From cb9eac565c8eed34146a6e299fdb724198922abf Mon Sep 17 00:00:00 2001 From: gaoruoshu Date: Tue, 20 Dec 2022 15:11:23 +0800 Subject: [PATCH] Added coloring aliases to fgrep egrep and grep --- colorgrep.csh | 11 +++++++++++ colorgrep.sh | 7 +++++++ grep.spec | 14 +++++++++++++- grepconf.sh | 11 +++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 colorgrep.csh create mode 100755 colorgrep.sh create mode 100755 grepconf.sh diff --git a/colorgrep.csh b/colorgrep.csh new file mode 100755 index 0000000..b3152a6 --- /dev/null +++ b/colorgrep.csh @@ -0,0 +1,11 @@ + +# color-grep initialization + +/usr/libexec/grepconf.sh -c +if ( $status == 1 ) then + exit +endif + +alias grep 'grep --color=auto' +alias egrep 'egrep --color=auto' +alias fgrep 'fgrep --color=auto' diff --git a/colorgrep.sh b/colorgrep.sh new file mode 100755 index 0000000..cd0539c --- /dev/null +++ b/colorgrep.sh @@ -0,0 +1,7 @@ +# color-grep initialization + +/usr/libexec/grepconf.sh -c || return + +alias grep='grep --color=auto' 2>/dev/null +alias egrep='egrep --color=auto' 2>/dev/null +alias fgrep='fgrep --color=auto' 2>/dev/null diff --git a/grep.spec b/grep.spec index b9ec77d..beaa8d9 100644 --- a/grep.spec +++ b/grep.spec @@ -1,10 +1,13 @@ Name: grep Version: 3.4 -Release: 1 +Release: 2 Summary: A string search utility License: GPLv3+ URL: http://www.gnu.org/software/grep/ Source0: https://ftp.gnu.org/gnu/grep/grep-%{version}.tar.xz +Source1: colorgrep.sh +Source2: colorgrep.csh +Source3: grepconf.sh Patch1: backport-grep-avoid-sticky-problem-with-f-f.patch @@ -28,6 +31,9 @@ CPPFLAGS="-I%{_includedir}/pcre" CFLAGS="$RPM_OPT_FLAGS" rm -f $RPM_BUILD_ROOT%{_infodir}/dir mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/profile.d +install -pm 644 %{SOURCE1} %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/profile.d +install -Dpm 755 %{SOURCE3} $RPM_BUILD_ROOT%{_libexecdir}/grepconf.sh + %pre %preun %post @@ -38,14 +44,20 @@ make check %files %{_datadir}/locale/* +%config(noreplace) %{_sysconfdir}/profile.d/colorgrep.*sh %doc NEWS README THANKS TODO %license COPYING AUTHORS %{_bindir}/*grep +%{_libexecdir}/grepconf.sh %{_infodir}/grep.info.gz %{_mandir}/man1/*grep.1.gz %changelog +* Tue Dec 20 2022 gaoruoshu - 3.4-2 +- Type:bugfix +- DESC:Added coloring aliases to fgrep egrep and grep + * Tue Feb 8 2022 yangzhuangzhuang - 3.4-1 - Type:bugfix - ID:NA diff --git a/grepconf.sh b/grepconf.sh new file mode 100755 index 0000000..418af0b --- /dev/null +++ b/grepconf.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +case "$1" in + -c | --interactive-color) + ! grep -qsi "^COLOR.*none" /etc/GREP_COLORS + ;; + *) + echo >&2 "Invalid / no option passed, so far only -c | --interactive-color is supported." + exit 1 + ;; +esac -- Gitee