@@ -20,6 +20,7 @@ const params_desc: []const u8 = blk: {
2020 \\-D, --no_dir Only show files, not directories. When used in conjunction with -d, neither is effective.
2121 \\-g, --git Show git status of files. Only effective when in long format.
2222 \\-e, --ext <str>... Filter by extension (e.g. --ext zig,md,ts).
23+ \\-m, --match <str>... Match file names/subtring (e.g. --match main,readme).
2324 \\<str>...
2425 \\
2526 ;
@@ -67,8 +68,10 @@ pub fn main(init: std.process.Init.Minimal) !void {
6768 var recursion_level : i8 = 0 ; // 0 means infinite
6869 var git : bool = false ;
6970 var exts : ? []const []const u8 = null ;
71+ var matches : ? []const []const u8 = null ;
7072
7173 var ext_list = try std .ArrayList ([]const u8 ).initCapacity (allocator , 0 );
74+ var match_list = try std .ArrayList ([]const u8 ).initCapacity (allocator , 0 );
7275
7376 var path : []const u8 = "." ;
7477
@@ -144,6 +147,23 @@ pub fn main(init: std.process.Init.Minimal) !void {
144147 exts = ext_list .items ;
145148 }
146149 }
150+ if (res .args .match .len > 0 ) {
151+ const match_args = res .args .match ;
152+ for (match_args ) | arg | {
153+ var token_it = std .mem .splitScalar (u8 , arg , ',' );
154+ while (token_it .next ()) | token | {
155+ const trimmed = std .mem .trim (u8 , token , " \t \r \n " );
156+ if (trimmed .len == 0 ) {
157+ continue ;
158+ }
159+
160+ try match_list .append (allocator , trimmed );
161+ }
162+ }
163+ if (match_list .items .len > 0 ) {
164+ matches = match_list .items ;
165+ }
166+ }
147167
148168 // get file path from args
149169 if (res .positionals [0 ].len > 0 ) {
@@ -158,7 +178,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
158178 allocator ,
159179 io ,
160180 dir ,
161- .{ .show_detail = show_detail , .show_hidden = show_hidden , .sort_type = sort_type , .recursive = recursive , .pure = pure , .only_dir = only_dir , .only_file = only_file , .recursion_level = recursion_level , .report = report , .show_git = git , .path = path , .exts = exts },
181+ .{ .show_detail = show_detail , .show_hidden = show_hidden , .sort_type = sort_type , .recursive = recursive , .pure = pure , .only_dir = only_dir , .only_file = only_file , .recursion_level = recursion_level , .report = report , .show_git = git , .path = path , .exts = exts , . matches = matches },
162182 );
163183 defer files .deinit ();
164184
0 commit comments