From 3a0bcb88b1cd832d3e26cfd7074c5344129f81a4 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 4 Nov 2023 22:00:57 +0100 Subject: bin/grepc, grepc.1: -A, -B, -C: Add flags for printing context. These flags are passed to pcre2grep(1). Signed-off-by: Alejandro Colomar --- bin/grepc | 17 ++++++++++++++++- share/man/man1/grepc.1 | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/bin/grepc b/bin/grepc index f1e105b..0123742 100755 --- a/bin/grepc +++ b/bin/grepc @@ -2,6 +2,9 @@ # Defaults: +A=''; +B=''; +C=''; c='no'; h='-H'; i=''; @@ -40,8 +43,17 @@ grepc_err() grepc_parse_cmd() { - while getopts "chiklt:" opt; do + while getopts "A:B:C:chiklt:" opt; do case "$opt" in + A) + A="-A$OPTARG"; + ;; + B) + B="-B$OPTARG"; + ;; + C) + C="-C$OPTARG"; + ;; c) c='yes'; ;; @@ -236,6 +248,9 @@ grepc_search() grepc_patterns "$identifier" >"$patterns"; + opts="$opts $A"; + opts="$opts $B"; + opts="$opts $C"; opts="$opts $h"; opts="$opts $i"; opts="$opts $l"; diff --git a/share/man/man1/grepc.1 b/share/man/man1/grepc.1 index 0e01781..ac124f3 100644 --- a/share/man/man1/grepc.1 +++ b/share/man/man1/grepc.1 @@ -122,6 +122,21 @@ Uses within type definitions .RE .SH OPTIONS .TP +.BI \-A \~n +Print +.I n +lines of trailing context after a match. +.TP +.BI \-B \~n +Print +.I n +lines of leading context before a match. +.TP +.BI \-C \~n +Print +.I n +lines of context surrounding a match. +.TP .B \-c Surround the matched strings with escape sequences to display them in color on the terminal. -- cgit v1.2.3