[latex3-commits] [latex3/l3sys-query] main: Add --pattern (d882fae)

github at latex-project.org github at latex-project.org
Thu Mar 7 14:41:15 CET 2024


Repository : https://github.com/latex3/l3sys-query
On branch  : main
Link       : https://github.com/latex3/l3sys-query/commit/d882fae2b28cbd99d6fddf562448e95098ed7442

>---------------------------------------------------------------

commit d882fae2b28cbd99d6fddf562448e95098ed7442
Author: Joseph Wright <joseph at texdev.net>
Date:   Thu Mar 7 13:41:15 2024 +0000

    Add --pattern


>---------------------------------------------------------------

d882fae2b28cbd99d6fddf562448e95098ed7442
 l3sys-query.lua | 17 ++++++++++++++---
 l3sys-query.tex | 10 ++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/l3sys-query.lua b/l3sys-query.lua
index cb9486c..884527b 100755
--- a/l3sys-query.lua
+++ b/l3sys-query.lua
@@ -72,6 +72,13 @@ local option_list =
         short = "h",
         type  = "boolean"
       },
+    pattern =
+      {
+        cmds  = {"ls"},
+        desc  = "Treat (x)args as a Lua pattern",
+        short = "p",
+        type  = "boolean"
+      },
     recursive =
       {
         cmds  = {"ls"},
@@ -163,7 +170,10 @@ end
    (c) 2008-2011 David Manura.  Licensed under the same terms as Lua (MIT).
 
 --]]
-local function glob_to_pattern(glob)
+local function glob_to_pattern(glob,skip_convert)
+  if skip_convert then
+    return glob
+  end
 
   local pattern = "^" -- pattern being built
   local i = 0 -- index in glob
@@ -446,14 +456,15 @@ function cmd_impl.ls(arg_list)
   if not match(path,"^%.") then
     path = "./" .. path
   end
-  local pattern = glob_to_pattern(glob)
+  local conv_pattern = options.pattern
+  local pattern = glob_to_pattern(glob,conv_pattern)
   local exclude_pattern
   if options.exclude then
     local exclude = options.exclude
     if match(exclude,"^'") and match(exclude,"'$") then
       exclude = sub(exclude,2,-2)
     end
-    exclude_pattern = glob_to_pattern(exclude)
+    exclude_pattern = glob_to_pattern(exclude,conv_pattern)
   end
   -- A lookup table for attributes: map between lfs- and Unix-type naming
   local attrib_map = {d = "directory", f = "file"}
diff --git a/l3sys-query.tex b/l3sys-query.tex
index 1abbfce..b3dd690 100644
--- a/l3sys-query.tex
+++ b/l3sys-query.tex
@@ -104,6 +104,8 @@ As well as these targets, the script recognizes the options
   \item |--all| Include \enquote{dot} entries in directory listings
   \item |--exclude| Specification for directory entries to exclude
   \item |--ignore-case| Ignores case when sorting directory listings
+  \item |--pattern| (|-p|) Treat the \meta{args} as Lua patterns rather
+    than converting from wildcards
   \item |--recursive| (|-r|) Enables recursive searching during directory
     listings
   \item |--reverse-sort| Causes sorting to go from highest to lowest rather
@@ -146,6 +148,14 @@ systems: these \enquote{dot} entries are excluded unless the |--all| option is
 set. Note that this will skip hidden directories entirely when used with the
 |--recursive| option.
 
+For more complex matching, the \meta{args} can be treated as a Lua pattern using
+the |--pattern| (|-p|) option; this also applies to the \meta{xarg} argument to
+the |--exclude| option. For example, the equivalent to wildcard |*.png| could be
+obtained using
+\begin{verbatim}
+  l3sys-query ls --pattern '^.*%.png$'
+\end{verbatim}
+
 Since \texttt{l3sys-query} is intended primarily for use with restricted shell
 escape calls from \TeX{} processes, handling of spaces is unusual. It is not
 possible to quote spaces in such a call, so for example whilst





More information about the latex3-commits mailing list.