add option "-a" ("--abbreviate")
3 files changed, 21 insertions(+), 5 deletions(-)

M ChangeLog.md
M README.md
M xgrep.py
M ChangeLog.md +7 -0
@@ 1,8 1,15 @@ 
+2020-04-26:
+
+* add option `-a` (`--abbreviate`)
+* bump version to 2.9
+
+
 2020-04-25:
 
 * add option `-M` (`--files-and-matches`)
 * bump version to 2.8
 
+
 2020-04-24:
 
 * rename option `-n` (`--declare-ns`) to `-N`

          
M README.md +5 -3
@@ 21,7 21,8 @@ On Debian-based systems, the prerequisit
 
 Usage:
 
-    xgrep.py [-c] [--count]
+    xgrep.py [-a] [--abbreviate]
+             [-c] [--count]
              [-C] [--force-color]
              [-i] [--indent]
              [-l] [--files-with-matches]

          
@@ 46,8 47,9 @@ parts are prefixed with the correspondin
 [EXSLT function `<ns>:test()`](http://exslt.org/regexp/functions/test/) can be
 used in the XPath expression for matching regular expressions. The option `-i`
 indents the matching parts, and the option `-N` includes namespace declarations.
-The `-C` option preserves color and formatting codes when piping output through
-[GNU less](http://www.gnu.org/software/less/) and similar programs.
+Matching parts can be abbreviated to their first line by means of the option
+`-a`. The `-C` option preserves color and formatting codes when piping output
+through [GNU less](http://www.gnu.org/software/less/) or similar programs.
 
 The options `-c`, `-l`, `-L`, `-n`, and `-q` mimic the behaviour of
 [GNU grep](http://www.gnu.org/software/grep/). The latter option suppresses any

          
M xgrep.py +9 -2
@@ 1,6 1,6 @@ 
 #! /usr/bin/python3
 # xgrep.py -- search for elements in XML files, using XPath 1.0 expressions
-# Andreas Nolda 2020-04-25
+# Andreas Nolda 2020-04-26
 
 import sys
 import argparse

          
@@ 8,13 8,15 @@ import re
 from blessings import Terminal
 from lxml import etree
 
-version=2.8
+version=2.9
 
 parser = argparse.ArgumentParser()
 parser.add_argument("expr",
                     help="XPath 1.0 expression")
 parser.add_argument("files", metavar="file", nargs="+",
                     help="XML file")
+parser.add_argument("-a", "--abbreviate", action="store_true",
+                    help="abbreviate matches")
 parser.add_argument("-c", "--count", action="store_true",
                     help="count matches")
 parser.add_argument("-C", "--force-color", action="store_true",

          
@@ 78,6 80,11 @@ def serialize_match(match):
                                 pretty_print=args.indent).decode()
     if not args.indent:
         string = re.sub("\n\s+", "\n", string)
+    if args.abbreviate:
+        lines = string.splitlines()
+        string = lines[0]
+        if len(lines) > 1:
+            string += " ..."
     if string.endswith("\n"):
         string = string[:-1]
     return string