summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/lua/mtx-grep.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-grep.lua')
-rw-r--r--Master/texmf-dist/scripts/context/lua/mtx-grep.lua35
1 files changed, 26 insertions, 9 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-grep.lua b/Master/texmf-dist/scripts/context/lua/mtx-grep.lua
index 3cbc1421ad2..dbcce67f6a2 100644
--- a/Master/texmf-dist/scripts/context/lua/mtx-grep.lua
+++ b/Master/texmf-dist/scripts/context/lua/mtx-grep.lua
@@ -7,12 +7,27 @@ if not modules then modules = { } end modules ['mtx-babel'] = {
}
local helpinfo = [[
---pattern search for pattern (optional)
---count count matches only
---nocomment skip lines that start with %% or #
---xml pattern is lpath expression
-
-patterns are lua patterns and need to be escaped accordingly
+<?xml version="1.0"?>
+<application>
+ <metadata>
+ <entry name="name">mtx-grep</entry>
+ <entry name="detail">Simple Grepper</entry>
+ <entry name="version">0.10</entry>
+ </metadata>
+ <flags>
+ <category name="basic">
+ <subcategory>
+ <flag name="pattern"><short>search for pattern (optional)</short></flag>
+ <flag name="count"><short>count matches only</short></flag>
+ <flag name="nocomment"><short>skip lines that start with %% or #</short></flag>
+ <flag name="xml"><short>pattern is lpath expression</short></flag>
+ </subcategory>
+ </category>
+ </flags>
+ <comments>
+ <comment>patterns are lua patterns and need to be escaped accordingly</comment>
+ </comments>
+</application>
]]
local application = logs.application {
@@ -60,7 +75,7 @@ function scripts.grep.find(pattern, files, offset)
if m > 0 then
nofmatches = nofmatches + m
nofmatchedfiles = nofmatchedfiles + 1
- write_nl(format("%s: %s",name,m))
+ write_nl(format("%5i %s",m,name))
io.flush()
end
else
@@ -127,7 +142,7 @@ function scripts.grep.find(pattern, files, offset)
if count and m > 0 then
nofmatches = nofmatches + m
nofmatchedfiles = nofmatchedfiles + 1
- write_nl(format("%s: %s",name,m))
+ write_nl(format("%5i %s",m,name))
io.flush()
end
end
@@ -144,7 +159,9 @@ end
local pattern = environment.argument("pattern")
local files = environment.files and #environment.files > 0 and environment.files
-if pattern and files then
+if environment.argument("exporthelp") then
+ application.export(environment.argument("exporthelp"),files[1])
+elseif pattern and files then
scripts.grep.find(pattern, files)
elseif files then
scripts.grep.find(files[1], files, 2)