-
Notifications
You must be signed in to change notification settings - Fork 0
/
rushex.py
5430 lines (5079 loc) · 274 KB
/
rushex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os.path
import pathlib
from itertools import tee
from list_all_files_recursively import get_folder_file_complete_path
import numexpr
from search_in_syspath import search_in_syspath
from textwrapre import wrapre
from pandas.core.frame import DataFrame, Series
from touchtouch import touch
import subprocess
from typing import Union
import pandas as pd
import re
import regex
import ujson
import numpy as np
from tempfile import SpooledTemporaryFile as tempfile
from flatten_everything import flatten_everything
try:
from cppradixsort import parallel_radixsort
def fast_reindex(df, *args, **kwargs):
indi = df.index.__array__().copy()
parallel_radixsort(indi)
return df.reindex(indi, *args, **kwargs)
def sort_series_copy(df):
indi = df.__array__().copy()
parallel_radixsort(indi)
return pd.Series(indi)
def sort_series_inpl(df):
indi = df.__array__()
parallel_radixsort(indi)
def pd_add_fastsort():
Series.s_fastsort_inplace = sort_series_inpl
Series.s_fastsort_copy = sort_series_copy
DataFrame.d_fast_reindex = fast_reindex
pd_add_fastsort()
except Exception:
pass
r"""
Wrapper for ripgrep by Johannes Fischer
Download RipGrep: https://github.com/BurntSushi/ripgrep
Original License:
The MIT License (MIT)
Copyright (c) 2015 Andrew Gallant
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE."""
def install_rip_grep(msvc_or_gnu = 'msvc'):
from downloadunzip import \
download_and_extract, tempfolder, \
copy_folder_to_another_folder
if msvc_or_gnu.lower().strip() == 'mscv':
url = r"https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep-13.0.0-x86_64-pc-windows-msvc.zip"
else:
url = 'https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep-13.0.0-x86_64-pc-windows-gnu.zip'
dest_dir = os.path.normpath(os.path.dirname(__file__))
tmpfo = tempfolder()
diditwork = download_and_extract(
url=url,
folder=tmpfo,
)
if diditwork:
copy_folder_to_another_folder(tmpfo, dest_dir)
return True
else:
return False
class Trie:
"""
Tr = Trie()
Tr.trie_regex_from_words(['ich', 'du', 'er', 'sie', 'es', 'wir', 'der', 'die', 'das'])
text = '''Der zur Verlagsgruppe Holtzbrinck gehörende Verlag S. Fischer hat bzw. hatte die Nutzungsrechte an Werken von Autoren wie Thomas und Heinrich Mann. Das Urheberrecht läuft in Deutschland erst 70 Jahre nach dem Tod des Autors aus. In den USA sind diese Werke aber schon vorher gemeinfrei (public domain), hier 56 Jahre nach Veröffentlichung.
Der Verlag ließ sich von der für Massenabmahnungen berüchtigten Kanzlei Waldorf Frommer vertreten.[7] Er forderte die Entfernung von 18 Werken, außerdem Schadenersatz und die Offenlegung aller IP-Adressen, von denen aus jene Werke heruntergeladen worden waren.
Das Landgericht Frankfurt am Main urteilte, dass die Werke in Deutschland unzugänglich gemacht werden dürfen, aber nicht entfernt werden müssen.[8] Die Serverlogs waren schon gelöscht, weshalb keine IPs herausgegeben werden konnten.
Als Folge des Urteils wurde das gesamte Angebot von Project Gutenberg für deutsche IP-Adressen gesperrt.
Der Verlag kritisierte die Praxis des Project Gutenberg, weil damit auch die übergroße Mehrzahl gemeinfreier Texte nicht mehr frei abrufbar sei, was nicht das Ziel der Klage gewesen sei. Dies lege „aus Sicht des Verlags doch den Schluss nahe, dass man die Nutzer instrumentalisieren und zu Protesten gegen den Verlag veranlassen will“.[9][10] Das Project Gutenberg sah sich andererseits der Gefahr ausgesetzt, auch wegen weiterer Titel mit derselben Problematik verklagt zu werden.[5]
Der 11. Zivilsenat des Oberlandesgerichts Frankfurt am Main (OLG) bestätigte mit Urteil vom 30. April 2019 – Az. 11 O 27/18 – die Entscheidung des Landgerichts.[11] Die Revision ließ das Oberlandesgericht Frankfurt nicht zu.[12] Gegen das Urteil des OLG Frankfurt war nur die Möglichkeit der Nichtzulassungsbeschwerde beim Bundesgerichtshof gegeben (Az. I ZR 97/19).[13]
Im Oktober 2021 wurde die Beilegung des Rechtsstreits bekannt gegeben. Die generelle Blockade deutscher IP-Adressen wurde aufgehoben, gesperrt sind lediglich noch die Werke der drei im Rechtsstreit benannten Autoren, soweit deren Urheberrecht in Deutschland noch nicht ausgelaufen ist.[4]'''
result = Tr.find(text)
print(result)
"""
def __init__(self):
self.data = {}
self.union = ""
def add(self, word):
ref = self.data
for char in word:
ref[char] = char in ref and ref[char] or {}
ref = ref[char]
ref[""] = 1
def dump(self):
return self.data
def quote(self, char):
return re.escape(char)
def _pattern(self, pData):
data = pData
if "" in data and len(data.keys()) == 1:
return None
alt = []
cc = []
q = 0
for char in sorted(data.keys()):
if isinstance(data[char], dict):
try:
recurse = self._pattern(data[char])
alt.append(self.quote(char) + recurse)
except:
cc.append(self.quote(char))
else:
q = 1
cconly = not len(alt) > 0
if len(cc) > 0:
if len(cc) == 1:
alt.append(cc[0])
else:
alt.append("[" + "".join(cc) + "]")
if len(alt) == 1:
result = alt[0]
else:
result = "(?:" + "|".join(alt) + ")"
if q:
if cconly:
result += "?"
else:
result = "(?:%s)?" % result
return result
def pattern(self):
return self._pattern(self.dump())
def trie_regex_from_words(
self,
words,
boundary_right=True,
boundary_left=True,
capture=False,
ignorecase=False,
match_whole_line=False,
):
for word in words:
self.add(word)
anfang = ""
ende = ""
if match_whole_line is True:
anfang = anfang + r"^\s*"
if boundary_right is True:
ende = ende + r"\b"
if capture is True:
anfang = anfang + "("
if boundary_left is True:
anfang = anfang + r"\b"
if capture is True:
ende = ende + ")"
if match_whole_line is True:
ende = ende + r"\s*$"
if ignorecase is True:
self.union = regex.compile(anfang + self.pattern() + ende, regex.IGNORECASE)
else:
self.union = regex.compile(anfang + self.pattern() + ende)
class PDTools:
def __init__(self, dataframe):
self.dataframe = dataframe
def bb_return_copy(self):
return self.dataframe.copy()
def aa_pd_horizonal_explode(
self,
what_columns: iter,
zfill: int = 4,
handle_nan: bool = True,
delete_old_cols: bool = True,
):
dataframe = self.bb_return_copy()
for col in what_columns:
if handle_nan:
pattern = dataframe[dataframe[col].isna()].index
if not pattern.empty:
howmanyelements = len(
dataframe.loc[~dataframe.index.isin(pattern), col].iloc[0]
)
dataframe.loc[pattern, col] = [[None] * howmanyelements] * len(
pattern
)
spittedlists = np.fromiter(
(
np.fromiter(_, dataframe[col].dtype)
for _ in zip(*dataframe[col].__array__())
),
dataframe[col].dtype,
)
for ini, splittedlist in enumerate(spittedlists):
dataframe[f"{col}_{str(ini).zfill(zfill)}"] = splittedlist
if delete_old_cols:
return dataframe.drop(columns=what_columns)
self.dataframe = dataframe.copy()
return self
class PyRipGREP:
def __init__(
self,
executeable=r"rg.exe",
option_targetfile=None,
):
self.tempfile_for_vars = "PyRipGREP.PyRtmp"
self.delete_tempfile_for_vars_search = False
self.executeable = executeable
self.necessary_beginning = [self.executeable]
self.options_parameters = {
"after_context": "--after-context",
"auto_hybrid_regex": "--auto-hybrid-regex",
"before_context": "--before-context",
"binary": "--binary",
"block_buffered": "--block-buffered",
"byte_offset": "--byte-offset",
"case_sensitive": "--case-sensitive",
"color": "--color",
"colors": "--colors",
"column": "--column",
"context": "--context",
"context_separator": "--context-separator",
"count": "--count",
"count_matches": "--count-matches",
"crlf": "--crlf",
"debug": "--debug",
"dfa_size_limit": "--dfa-size-limit",
"encoding": "--encoding",
"engine": "--engine",
"field_context_separator": "--field-context-separator",
"field_match_separator": "--field-match-separator",
"file": "--file",
"files": "--files",
"files_with_matches": "--files-with-matches",
"files_without_match": "--files-without-match",
"fixed_strings": "--fixed-strings",
"follow": "--follow",
"glob": "--glob",
"glob_case_insensitive": "--glob-case-insensitive",
"help": "--help",
"heading": "--heading",
"hidden": "--hidden",
"iglob": "--iglob",
"ignore_case": "--ignore-case",
"ignore_file": "--ignore-file",
"ignore_file_case_insensitive": "--ignore-file-case-insensitive",
"include_zero": "--include-zero",
"invert_match": "--invert-match",
"json": "--json",
"line_buffered": "--line-buffered",
"line_number": "--line-number",
"line_regexp": "--line-regexp",
"max_columns": "--max-columns",
"max_columns_preview": "--max-columns-preview",
"max_count": "--max-count",
"max_depth": "--max-depth",
"max_filesize": "--max-filesize",
"mmap": "--mmap",
"multiline": "--multiline",
"multiline_dotall": "--multiline-dotall",
"no_config": "--no-config",
"no_filename": "--no-filename",
"no_heading": "--no-heading",
"no_ignore": "--no-ignore",
"no_ignore_dot": "--no-ignore-dot",
"no_ignore_exclude": "--no-ignore-exclude",
"no_ignore_files": "--no-ignore-files",
"no_ignore_global": "--no-ignore-global",
"no_ignore_messages": "--no-ignore-messages",
"no_ignore_parent": "--no-ignore-parent",
"no_ignore_vcs": "--no-ignore-vcs",
"no_line_number": "--no-line-number",
"no_messages": "--no-messages",
"no_mmap": "--no-mmap",
"no_pcre2_unicode": "--no-pcre2-unicode",
"no_require_git": "--no-require-git",
"no_unicode": "--no-unicode",
"null": "--null",
"null_data": "--null-data",
"one_file_system": "--one-file-system",
"only_matching": "--only-matching",
"passthru": "--passthru",
"path_separator": "--path-separator",
"pcre2": "--pcre2",
"pcre2_version": "--pcre2-version",
"pre": "--pre",
"pretty": "--pretty",
"quiet": "--quiet",
"regex_size_limit": "--regex-size-limit",
"regexp": "--regexp",
"replace": "--replace",
"search_zip": "--search-zip",
"smart_case": "--smart-case",
"sort": "--sort",
"sortr": "--sortr",
"stats": "--stats",
"text": "--text",
"threads": "--threads",
"trim": "--trim",
"type": "--type",
"type_add": "--type-add",
"type_clear": "--type-clear",
"type_list": "--type-list",
"type_not": "--type-not",
"unrestricted": "--unrestricted",
"version": "--version",
"vimgrep": "--vimgrep",
"with_filename": "--with-filename",
"word_regexp": "--word-regexp",
}
self.execute_dict = {
"--after-context": False,
"--auto-hybrid-regex": False,
"--before-context": False,
"--binary": False,
"--block-buffered": False,
"--byte-offset": False,
"--case-sensitive": False,
"--color": False,
"--colors": False,
"--column": False,
"--context": False,
"--context-separator": False,
"--count": False,
"--count-matches": False,
"--crlf": False,
"--debug": False,
"--dfa-size-limit": False,
"--encoding": False,
"--engine": False,
"--field-context-separator": False,
"--field-match-separator": False,
"--file": False,
"--files": False,
"--files-with-matches": False,
"--files-without-match": False,
"--fixed-strings": False,
"--follow": False,
"--glob": False,
"--glob-case-insensitive": False,
"--help": False,
"--heading": False,
"--hidden": False,
"--iglob": False,
"--ignore-case": False,
"--ignore-file": False,
"--ignore-file-case-insensitive": False,
"--include-zero": False,
"--invert-match": False,
"--json": False,
"--line-buffered": False,
"--line-number": False,
"--line-regexp": False,
"--max-columns": False,
"--max-columns-preview": False,
"--max-count": False,
"--max-depth": False,
"--max-filesize": False,
"--mmap": False,
"--multiline": False,
"--multiline-dotall": False,
"--no-config": False,
"--no-filename": False,
"--no-heading": False,
"--no-ignore": False,
"--no-ignore-dot": False,
"--no-ignore-exclude": False,
"--no-ignore-files": False,
"--no-ignore-global": False,
"--no-ignore-messages": False,
"--no-ignore-parent": False,
"--no-ignore-vcs": False,
"--no-line-number": False,
"--no-messages": False,
"--no-mmap": False,
"--no-pcre2-unicode": False,
"--no-require-git": False,
"--no-unicode": False,
"--null": False,
"--null-data": False,
"--one-file-system": False,
"--only-matching": False,
"--passthru": False,
"--path-separator": False,
"--pcre2": False,
"--pcre2-version": False,
"--pre": False,
"--pretty": False,
"--quiet": False,
"--regex-size-limit": False,
"--regexp": False,
"--replace": False,
"--search-zip": False,
"--smart-case": False,
"--sort": False,
"--sortr": False,
"--stats": False,
"--text": False,
"--threads": False,
"--trim": False,
"--type": False,
"--type-add": False,
"--type-clear": False,
"--type-list": False,
"--type-not": False,
"--unrestricted": False,
"--version": False,
"--vimgrep": False,
"--with-filename": False,
"--word-regexp": False,
}
self.helpdict = {
"after_context": " Show NUM lines after each match. This overrides the --context and --passthru flags.",
"auto_hybrid_regex": " DEPRECATED. Use --engine instead. When this flag is used, ripgrep will dynamically choose between\nsupported regex engines depending on the features used in a pattern. When ripgrep chooses a regex\nengine, it applies that choice for every regex provided to ripgrep (e.g., via multiple -e/--regexp\nor -f/--file flags). As an example of how this flag might behave, ripgrep will attempt to use its\ndefault finite automata based regex engine whenever the pattern can be successfully compiled with\nthat regex engine. If PCRE2 is enabled and if the pattern given could not be compiled with the\ndefault regex engine, then PCRE2 will be automatically used for searching. If PCRE2 isn't available,\nthen this flag has no effect because there is only one regex engine to choose from. In the future,\nripgrep may adjust its heuristics for how it decides which regex engine to use. In general, the\nheuristics will be limited to a static analysis of the patterns, and not to any specific runtime\nbehavior observed while searching files. The primary downside of using this flag is that it may not\nalways be obvious which regex engine ripgrep uses, and thus, the match semantics or performance\nprofile of ripgrep may subtly and unexpectedly change. However, in many cases, all regex engines\nwill agree on what constitutes a match and it can be nice to transparently support more advanced\nregex features like look-around and backreferences without explicitly needing to enable them. This\nflag can be disabled with --no-auto-hybrid-regex.",
"before_context": " Show NUM lines before each match. This overrides the --context and --passthru flags.",
"binary": " Enabling this flag will cause ripgrep to search binary files. By default, ripgrep attempts to\nautomatically skip binary files in order to improve the relevance of results and make the search\nfaster. Binary files are heuristically detected based on whether they contain a NUL byte or not. By\ndefault (without this flag set), once a NUL byte is seen, ripgrep will stop searching the file.\nUsually, NUL bytes occur in the beginning of most binary files. If a NUL byte occurs after a match,\nthen ripgrep will still stop searching the rest of the file, but a warning will be printed. In\ncontrast, when this flag is provided, ripgrep will continue searching a file even if a NUL byte is\nfound. In particular, if a NUL byte is found then ripgrep will continue searching until either a\nmatch is found or the end of the file is reached, whichever comes sooner. If a match is found, then\nripgrep will stop and print a warning saying that the search stopped prematurely. If you want\nripgrep to search a file without any special NUL byte handling at all (and potentially print binary\ndata to stdout), then you should use the '-a/--text' flag. The '--binary' flag is a flag for\ncontrolling ripgrep's automatic filtering mechanism. As such, it does not need to be used when\nsearching a file explicitly or when searching stdin. That is, it is only applicable when recursively\nsearching a directory. Note that when the '-u/--unrestricted' flag is provided for a third time,\nthen this flag is automatically enabled. This flag can be disabled with '--no-binary'. It overrides\nthe '-a/--text' flag.",
"block_buffered": " When enabled, ripgrep will use block buffering. That is, whenever a matching line is found, it will\nbe written to an in-memory buffer and will not be written to stdout until the buffer reaches a\ncertain size. This is the default when ripgrep's stdout is redirected to a pipeline or a file. When\nripgrep's stdout is connected to a terminal, line buffering will be used. Forcing block buffering\ncan be useful when dumping a large amount of contents to a terminal. Forceful block buffering can\nbe disabled with --no-block-buffered. Note that using --no-block-buffered causes ripgrep to revert\nto its default behavior of automatically detecting the buffering strategy. To force line buffering,\nuse the --line-buffered flag.",
"byte_offset": " Print the 0-based byte offset within the input file before each line of output. If -o (--only-\nmatching) is specified, print the offset of the matching part itself. If ripgrep does transcoding,\nthen the byte offset is in terms of the the result of transcoding and not the original data. This\napplies similarly to another transformation on the source, such as decompression or a --pre filter.\nNote that when the PCRE2 regex engine is used, then UTF-8 transcoding is done by default.",
"case_sensitive": " Search case sensitively. This overrides the -i/--ignore-case and -S/--smart-case flags.",
"color": " This flag controls when to use colors. The default setting is 'auto', which means ripgrep will try\nto guess when to use colors. For example, if ripgrep is printing to a terminal, then it will use\ncolors, but if it is redirected to a file or a pipe, then it will suppress color output. ripgrep\nwill suppress color output in some other circumstances as well. For example, if the TERM environment\nsearch_in is not set or set to 'dumb', then ripgrep will not use colors. The possible values for\nthis flag are: never Colors will never be used. auto The default. ripgrep tries to be smart.\nalways Colors will always be used regardless of where output is sent. ansi Like 'always', but\nemits ANSI escapes (even in a Windows console). When the --vimgrep flag is given to ripgrep, then\nthe default value for the color flag changes to 'never'.",
"colors": " This flag specifies color settings for use in the output. This flag may be provided multiple times.\nSettings are applied iteratively. Colors are limited to one of eight choices: red, blue, green,\ncyan, magenta, yellow, white and black. Styles are limited to nobold, bold, nointense, intense,\nnounderline or underline. The format of the flag is '{type}:{attribute}:{value}'. '{type}' should\nbe one of path, line, column or match. '{attribute}' can be fg, bg or style. '{value}' is either a\ncolor (for fg and bg) or a text style. A special format, '{type}:none', will clear all color\nsettings for '{type}'. For example, the following command will change the match color to magenta\nand the background color for line numbers to yellow: rg --colors 'match:fg:magenta' --colors\n'line:bg:yellow' foo. Extended colors can be used for '{value}' when the terminal supports ANSI\ncolor sequences. These are specified as either 'x' (256-color) or 'x,x,x' (24-bit truecolor) where x\nis a number between 0 and 255 inclusive. x may be given as a normal decimal number or a hexadecimal\nnumber, which is prefixed by `0x`. For example, the following command will change the match\nbackground color to that represented by the rgb value (0,128,255): rg --colors 'match:bg:0,128,255'\nor, equivalently, rg --colors 'match:bg:0x0,0x80,0xFF' Note that the the intense and nointense\nstyle flags will have no effect when used alongside these extended color codes.",
"column": " Show column numbers (1-based). This only shows the column numbers for the first match on each line.\nThis does not try to account for Unicode. One byte is equal to one column. This implies --line-\nnumber. This flag can be disabled with --no-column.",
"context": " Show NUM lines before and after each match. This is equivalent to providing both the -B/--before-\ncontext and -A/--after-context flags with the same value. This overrides both the -B/--before-\ncontext and -A/--after-context flags, in addition to the --passthru flag.",
"context_separator": " The string used to separate non-contiguous context lines in the output. This is only used when one\nof the context flags is used (-A, -B or -C). Escape sequences like \x7f or may be used. The\ndefault value is --. When the context separator is set to an empty string, then a line break is\nstill inserted. To completely disable context separators, use the no-context-separator flag.",
"count": " This flag suppresses normal output and shows the number of lines that match the given patterns for\neach file searched. Each file containing a match has its path and count printed on each line. Note\nthat this reports the number of lines that match and not the total number of matches, unless\n-U/--multiline is enabled. In multiline mode, --count is equivalent to --count-matches. If only one\nfile is given to ripgrep, then only the count is printed if there is a match. The --with-filename\nflag can be used to force printing the file path in this case. If you need a count to be printed\nregardless of whether there is a match, then use --include-zero. This overrides the --count-matches\nflag. Note that when --count is combined with --only-matching, then ripgrep behaves as if --count-\nmatches was given.",
"count_matches": " This flag suppresses normal output and shows the number of individual matches of the given patterns\nfor each file searched. Each file containing matches has its path and match count printed on each\nline. Note that this reports the total number of individual matches and not the number of lines that\nmatch. If only one file is given to ripgrep, then only the count is printed if there is a match.\nThe --with-filename flag can be used to force printing the file path in this case. This overrides\nthe --count flag. Note that when --count is combined with only-matching, then ripgrep behaves as if\n--count-matches was given.",
"crlf": " When enabled, ripgrep will treat CRLF (') as a line terminator instead of just '. Principally,\nthis permits '$' in regex patterns to match just before CRLF instead of just before LF. The\nunderlying regex engine may not support this natively, so ripgrep will translate all instances of\n'$' to '(?:??$)'. This may produce slightly different than desired match offsets. It is intended as\na work-around until the regex engine supports this natively. CRLF support can be disabled with\n--no-crlf.",
"debug": " Show debug messages. Please use this when filing a bug report. The --debug flag is generally\nuseful for figuring out why ripgrep skipped searching a particular file. The debug messages should\nmention all files skipped and why they were skipped. To get even more debug output, use the --trace\nflag, which implies --debug along with additional trace data. With --trace, the output could be\nquite large and is generally more useful for development.",
"dfa_size_limit": " The upper size limit of the regex DFA. The default limit is 10M. This should only be changed on\nvery large regex inputs where the (slower) fallback regex engine may otherwise be used if the limit\nis reached. The argument accepts the same size suffixes as allowed in with the max-filesize flag.",
"encoding": " Specify the text encoding that ripgrep will use on all files searched. The default value is 'auto',\nwhich will cause ripgrep to do a best effort automatic detection of encoding on a per-file basis.\nAutomatic detection in this case only applies to files that begin with a UTF-8 or UTF-16 byte-order\nmark (BOM). No other automatic detection is performed. One can also specify 'none' which will then\ncompletely disable BOM sniffing and always result in searching the raw bytes, including a BOM if\nit's present, regardless of its encoding. Other supported values can be found in the list of labels\nhere: https://encoding.spec.whatwg.org/#concept-encoding-get For more details on encoding and how\nripgrep deals with it, see GUIDE.md. This flag can be disabled with --no-encoding.",
"engine": " Specify which regular expression engine to use. When you choose a regex engine, it applies that\nchoice for every regex provided to ripgrep (e.g., via multiple -e/--regexp or -f/--file flags).\nAccepted values are 'default', 'pcre2', or 'auto'. The default value is 'default', which is the\nfastest and should be good for most use cases. The 'pcre2' engine is generally useful when you want\nto use features such as look-around or backreferences. 'auto' will dynamically choose between\nsupported regex engines depending on the features used in a pattern on a best effort basis. Note\nthat the 'pcre2' engine is an optional ripgrep feature. If PCRE2 wasn't included in your build of\nripgrep, then using this flag will result in ripgrep printing an error message and exiting. This\noverrides previous uses of --pcre2 and --auto-hybrid-regex flags. [default: default]",
"field_context_separator": " Set the field context separator, which is used to delimit file paths, line numbers, columns and the\ncontext itself, when printing contextual lines. The separator may be any number of bytes, including\nzero. Escape sequences like \x7f or may be used. The default value is -.",
"field_match_separator": " Set the field match separator, which is used to delimit file paths, line numbers, columns and the\nmatch itself. The separator may be any number of bytes, including zero. Escape sequences like \x7f or\nmay be used. The default value is -.",
"file": " Search for patterns from the given file, with one pattern per line. When this flag is used multiple\ntimes or in combination with the -e/--regexp flag, then all patterns provided are searched. Empty\npattern lines will match all input lines, and the newline is not counted as part of the pattern. A\nline is printed if and only if it matches at least one of the patterns.",
"files": " Print each file that would be searched without actually performing the search. This is useful to\ndetermine whether a particular file is being searched or not.",
"files_with_matches": " Print the paths with at least one match and suppress match contents. This overrides --files-\nwithout-match.",
"files_without_match": " Print the paths that contain zero matches and suppress match contents. This inverts/negates the\n--files-with-matches flag. This overrides --files-with-matches.",
"fixed_strings": " Treat the pattern as a literal string instead of a regular expression. When this flag is used,\nspecial regular expression meta characters such as .(){}*+ do not need to be escaped. This flag can\nbe disabled with --no-fixed-strings.",
"follow": " When this flag is enabled, ripgrep will follow symbolic links while traversing directories. This is\ndisabled by default. Note that ripgrep will check for symbolic link loops and report errors if it\nfinds one. This flag can be disabled with --no-follow.",
"glob": " Include or exclude files and directories for searching that match the given glob. This always\noverrides any other ignore logic. Multiple glob flags may be used. Globbing rules match .gitignore\nglobs. Precede a glob with a ! to exclude it. If multiple globs match a file or directory, the glob\ngiven later in the command line takes precedence. As an extension, globs support specifying\nalternatives: *-g ab{c,d}* is equivalet to *-g abc -g abd*. Empty alternatives like *-g ab{,c}* are\nnot currently supported. Note that this syntax extension is also currently enabled in gitignore\nfiles, even though this syntax isn't supported by git itself. ripgrep may disable this syntax\nextension in gitignore files, but it will always remain available via the -g/--glob flag. When this\nflag is set, every file and directory is applied to it to test for a match. So for example, if you\nonly want to search in a particular directory 'foo', then *-g foo* is incorrect because 'foo/bar'\ndoes not match the glob 'foo'. Instead, you should use *-g 'foo/**'*.",
"glob_case_insensitive": " Process glob patterns given with the -g/--glob flag case insensitively. This effectively treats\n--glob as --iglob. This flag can be disabled with the --no-glob-case-insensitive flag.",
"help": " Prints help information. Use --help for more details.",
"heading": " This flag prints the file path above clusters of matches from each file instead of printing the\nfile path as a prefix for each matched line. This is the default mode when printing to a terminal.\nThis overrides the --no-heading flag.",
"hidden": " Search hidden files and directories. By default, hidden files and directories are skipped. Note\nthat if a hidden file or a directory is whitelisted in an ignore file, then it will be searched even\nif this flag isn't provided. A file or directory is considered hidden if its base name starts with\na dot character ('.'). On operating systems which support a `hidden` file attribute, like Windows,\nfiles with this attribute are also considered hidden. This flag can be disabled with --no-hidden.",
"iglob": " Include or exclude files and directories for searching that match the given glob. This always\noverrides any other ignore logic. Multiple glob flags may be used. Globbing rules match .gitignore\nglobs. Precede a glob with a ! to exclude it. Globs are matched case insensitively.",
"ignore_case": ' When this flag is provided, the given patterns will be searched case insensitively. The case\ninsensitivity rules used by ripgrep conform to Unicode\'s "simple" case folding rules. This flag\noverrides -s/--case-sensitive and -S/--smart-case.',
"ignore_file": " Specifies a path to one or more .gitignore format rules files. These patterns are applied after the\npatterns found in .gitignore and .ignore are applied and are matched relative to the current working\ndirectory. Multiple additional ignore files can be specified by using the --ignore-file flag several\ntimes. When specifying multiple ignore files, earlier files have lower precedence than later files.\nIf you are looking for a way to include or exclude files and directories directly on the command\nline, then used -g instead.",
"ignore_file_case_insensitive": " Process ignore files (.gitignore, .ignore, etc.) case insensitively. Note that this comes with a\nperformance penalty and is most useful on case insensitive file systems (such as Windows). This\nflag can be disabled with the --no-ignore-file-case-insensitive flag.",
"include_zero": " When used with --count or --count-matches, print the number of matches for each file even if there\nwere zero matches. This is disabled by default but can be enabled to make ripgrep behave more like\ngrep.",
"invert_match": " Invert matching. Show lines that do not match the given patterns.",
"json": " Enable printing results in a JSON Lines format. When this flag is provided, ripgrep will emit a\nsequence of messages, each encoded as a JSON object, where there are five different message types:\n**begin** - A message that indicates a file is being searched and contains at least one match.\n**end** - A message the indicates a file is done being searched. This message also include summary\nstatistics about the search for a particular file. **match** - A message that indicates a match was\nfound. This includes the text and offsets of the match. **context** - A message that indicates a\ncontextual line was found. This includes the text of the line, along with any match information if\nthe search was inverted. **summary** - The final message emitted by ripgrep that contains summary\nstatistics about the search across all files. Since file paths or the contents of files are not\nguaranteed to be valid UTF-8 and JSON itself must be representable by a Unicode encoding, ripgrep\nwill emit all data elements as objects with one of two keys: 'text' or 'bytes'. 'text' is a normal\nJSON string when the data is valid UTF-8 while 'bytes' is the base64 encoded contents of the data.\nThe JSON Lines format is only supported for showing search results. It cannot be used with other\nflags that emit other types of output, such as --files, files-with-matches, --files-without-match,\n--count or --count-matches. ripgrep will report an error if any of the aforementioned flags are used\nin concert with --json. Other flags that control aspects of the standard output such as only-\nmatching, --heading, --replace, --max-columns, etc., have no effect when --json is set. A more\ncomplete description of the JSON format used can be found here: https://docs.rs/grep-\nprinter/*/grep_printer/struct.JSON.html The JSON Lines format can be disabled with --no-json.",
"line_buffered": " When enabled, ripgrep will use line buffering. That is, whenever a matching line is found, it will\nbe flushed to stdout immediately. This is the default when ripgrep's stdout is connected to a\nterminal, but otherwise, ripgrep will use block buffering, which is typically faster. This flag\nforces ripgrep to use line buffering even if it would otherwise use block buffering. This is\ntypically useful in shell pipelines, e.g., 'tail -f something.log | rg foo --line-buffered | rg\nbar'. Forceful line buffering can be disabled with --no-line-buffered. Note that using --no-line-\nbuffered causes ripgrep to revert to its default behavior of automatically detecting the buffering\nstrategy. To force block buffering, use the --block-buffered flag.",
"line_number": " Show line numbers (1-based). This is enabled by default when searching in a terminal.",
"line_regexp": " Only show matches surrounded by line boundaries. This is equivalent to putting ^...$ around all of\nthe search patterns. In other words, this only prints lines where the entire line participates in a\nmatch. This overrides the --word-regexp flag.",
"max_columns": " Don't print lines longer than this limit in bytes. Longer lines are omitted, and only the number of\nmatches in that line is printed. When this flag is omitted or is set to 0, then it has no effect.",
"max_columns_preview": " When the '--max-columns' flag is used, ripgrep will by default completely replace any line that is\ntoo long with a message indicating that a matching line was removed. When this flag is combined with\n'--max-columns', a preview of the line (corresponding to the limit size) is shown instead, where the\npart of the line exceeding the limit is not shown. If the '--max-columns' flag is not set, then\nthis has no effect. This flag can be disabled with '--no-max-columns-preview'.",
"max_count": " Limit the number of matching lines per file searched to NUM.",
"max_depth": " Limit the depth of directory traversal to NUM levels beyond the paths given. A value of zero only\nsearches the explicitly given paths themselves. For example, 'rg --max-depth 0 dir/' is a no-op\nbecause dir/ will not be descended into. 'rg --max-depth 1 dir/' will search only the direct\nchildren of 'dir'.",
"max_filesize": " Ignore files larger than NUM in size. This does not apply to directories. The input format accepts\nsuffixes of K, M or G which correspond to kilobytes, megabytes and gigabytes, respectively. If no\nsuffix is provided the input is treated as bytes. Examples: --max-filesize 50K or --max-filesize\n80M",
"mmap": " Search using memory maps when possible. This is enabled by default when ripgrep thinks it will be\nfaster. Memory map searching doesn't currently support all options, so if an incompatible option\n(e.g., --context) is given with --mmap, then memory maps will not be used. Note that ripgrep may\nabort unexpectedly when --mmap if it searches a file that is simultaneously truncated. This flag\noverrides --no-mmap.",
"multiline": " Enable matching across multiple lines. When multiline mode is enabled, ripgrep will lift the\nrestriction that a match cannot include a line terminator. For example, when multiline mode is not\nenabled (the default), then the regex '\\p{any}' will match any Unicode codepoint other than '.\nSimilarly, the regex ' is explicitly forbidden, and if you try to use it, ripgrep will return an\nerror. However, when multiline mode is enabled, '\\p{any}' will match any Unicode codepoint,\nincluding ', and regexes like ' are permitted. An important caveat is that multiline mode does\nnot change the match semantics of '.'. Namely, in most regex matchers, a '.' will by default match\nany character other than ', and this is true in ripgrep as well. In order to make '.' match ', you\nmust enable the \"dot all\" flag inside the regex. For example, both '(?s).' and '(?s:.)' have the\nsame semantics, where '.' will match any character, including '. Alternatively, the '--multiline-\ndotall' flag may be passed to make the \"dot all\" behavior the default. This flag only applies when\nmultiline search is enabled. There is no limit on the number of the lines that a single match can\nspan. **WARNING**: Because of how the underlying regex engine works, multiline searches may be\nslower than normal line-oriented searches, and they may also use more memory. In particular, when\nmultiline mode is enabled, ripgrep requires that each file it searches is laid out contiguously in\nmemory (either by reading it onto the heap or by memory-mapping it). Things that cannot be memory-\nmapped (such as stdin) will be consumed until EOF before searching can begin. In general, ripgrep\nwill only do these things when necessary. Specifically, if the --multiline flag is provided but the\nregex does not contain patterns that would match ' characters, then ripgrep will automatically\navoid reading each file into memory before searching it. Nevertheless, if you only care about\nmatches spanning at most one line, then it is always better to disable multiline mode. This flag\ncan be disabled with --no-multiline.",
"multiline_dotall": " This flag enables \"dot all\" in your regex pattern, which causes '.' to match newlines when\nmultiline searching is enabled. This flag has no effect if multiline searching isn't enabled with\nthe --multiline flag. Normally, a '.' will match any character except newlines. While this behavior\ntypically isn't relevant for line-oriented matching (since matches can span at most one line), this\ncan be useful when searching with the -U/--multiline flag. By default, the multiline mode runs\nwithout this flag. This flag is generally intended to be used in an alias or your ripgrep config\nfile if you prefer \"dot all\" semantics by default. Note that regardless of whether this flag is\nused, \"dot all\" semantics can still be controlled via inline flags in the regex pattern itself,\ne.g., '(?s:.)' always enables \"dot all\" whereas '(?-s:.)' always disables \"dot all\". This flag can\nbe disabled with --no-multiline-dotall.",
"no_config": " Never read configuration files. When this flag is present, ripgrep will not respect the\nRIPGREP_CONFIG_PATH environment search_in. If ripgrep ever grows a feature to automatically read\nconfiguration files in pre-defined locations, then this flag will also disable that behavior as\nwell.",
"no_filename": " Never print the file path with the matched lines. This is the default when ripgrep is explicitly\ninstructed to search one file or stdin. This flag overrides --with-filename.",
"no_heading": " Don't group matches by each file. If --no-heading is provided in addition to the -H/--with-filename\nflag, then file paths will be printed as a prefix for every matched line. This is the default mode\nwhen not printing to a terminal. This overrides the --heading flag.",
"no_ignore": " Don't respect ignore files (.gitignore, .ignore, etc.). This implies no-ignore-dot, --no-ignore-\nexclude, --no-ignore-global, no-ignore-parent and no-ignore-vcs. This does *not* imply --no-ignore-\nfiles, since --ignore-file is specified explicitly as a command line argument. When given only\nonce, the -u flag is identical in behavior to --no-ignore and can be considered an alias. However,\nsubsequent -u flags have additional effects; see --unrestricted. This flag can be disabled with the\n--ignore flag.",
"no_ignore_dot": " Don't respect .ignore files. This does *not* affect whether ripgrep will ignore files and\ndirectories whose names begin with a dot. For that, see the -./--hidden flag. This flag can be\ndisabled with the --ignore-dot flag.",
"no_ignore_exclude": " Don't respect ignore files that are manually configured for the repository such as git's\n'.git/info/exclude'. This flag can be disabled with the --ignore-exclude flag.",
"no_ignore_files": " When set, any --ignore-file flags, even ones that come after this flag, are ignored. This flag can\nbe disabled with the --ignore-files flag.",
"no_ignore_global": " Don't respect ignore files that come from \"global\" sources such as git's `core.excludesFile`\nconfiguration option (which defaults to `$HOME/.config/git/ignore`). This flag can be disabled with\nthe --ignore-global flag.",
"no_ignore_messages": " Suppresses all error messages related to parsing ignore files such as .ignore or .gitignore. This\nflag can be disabled with the --ignore-messages flag.",
"no_ignore_parent": " Don't respect ignore files (.gitignore, .ignore, etc.) in parent directories. This flag can be\ndisabled with the --ignore-parent flag.",
"no_ignore_vcs": " Don't respect version control ignore files (.gitignore, etc.). This implies no-ignore-parent for\nVCS files. Note that .ignore files will continue to be respected. This flag can be disabled with\nthe --ignore-vcs flag.",
"no_line_number": " Suppress line numbers. This is enabled by default when not searching in a terminal.",
"no_messages": " Suppress all error messages related to opening and reading files. Error messages related to the\nsyntax of the pattern given are still shown. This flag can be disabled with the --messages flag.",
"no_mmap": " Never use memory maps, even when they might be faster. This flag overrides --mmap.",
"no_pcre2_unicode": " DEPRECATED. Use --no-unicode instead. This flag is now an alias for --no-unicode. And\n--pcre2-unicode is an alias for --unicode.",
"no_require_git": " By default, ripgrep will only respect global gitignore rules, .gitignore rules and local exclude\nrules if ripgrep detects that you are searching inside a git repository. This flag allows you to\nrelax this restriction such that ripgrep will respect all git related ignore rules regardless of\nwhether you're searching in a git repository or not. This flag can be disabled with --require-git.",
"no_unicode": " By default, ripgrep will enable \"Unicode mode\" in all of its regexes. This has a number of\nconsequences: * '.' will only match valid UTF-8 encoded scalar values. * Classes like '\\w', '\\s',\n'\\d' are all Unicode aware and much bigger than their ASCII only versions. * Case insensitive\nmatching will use Unicode case folding. * A large array of classes like '\\p{Emoji}' are available. *\nWord boundaries ('\x08' and '\\B') use the Unicode definition of a word character. In some cases it can\nbe desirable to turn these things off. The --no-unicode flag will do exactly that. For PCRE2\nspecifically, Unicode mode represents a critical trade off in the user experience of ripgrep. In\nparticular, unlike the default regex engine, PCRE2 does not support the ability to search possibly\ninvalid UTF-8 with Unicode features enabled. Instead, PCRE2 *requires* that everything it searches\nwhen Unicode mode is enabled is valid UTF-8. (Or valid UTF-16/UTF-32, but for the purposes of\nripgrep, we only discuss UTF-8.) This means that if you have PCRE2's Unicode mode enabled and you\nattempt to search invalid UTF-8, then the search for that file will halt and print an error. For\nthis reason, when PCRE2's Unicode mode is enabled, ripgrep will automatically \"fix\" invalid UTF-8\nsequences by replacing them with the Unicode replacement codepoint. This penalty does not occur when\nusing the default regex engine. If you would rather see the encoding errors surfaced by PCRE2 when\nUnicode mode is enabled, then pass the --no-encoding flag to disable all transcoding. The --no-\nunicode flag can be disabled with --unicode. Note that no-pcre2-unicode and --pcre2-unicode are\naliases for --no-unicode and unicode, respectively.",
"null": " Whenever a file path is printed, follow it with a NUL byte. This includes printing file paths\nbefore matches, and when printing a list of matching files such as with --count, --files-with-\nmatches and --files. This option is useful for use with xargs.",
"null_data": " Enabling this option causes ripgrep to use NUL as a line terminator instead of the default of '.\nThis is useful when searching large binary files that would otherwise have very long lines if '\nwere used as the line terminator. In particular, ripgrep requires that, at a minimum, each line must\nfit into memory. Using NUL instead can be a useful stopgap to keep memory requirements low and avoid\nOOM (out of memory) conditions. This is also useful for processing NUL delimited data, such as that\nemitted when using ripgrep's -0/--null flag or find's --print0 flag. Using this flag implies\n-a/--text.",
"one_file_system": " When enabled, ripgrep will not cross file system boundaries relative to where the search started\nfrom. Note that this applies to each path argument given to ripgrep. For example, in the command\n'rg --one-file-system /foo/bar /quux/baz', ripgrep will search both '/foo/bar' and '/quux/baz' even\nif they are on different file systems, but will not cross a file system boundary when traversing\neach path's directory tree. This is similar to find's '-xdev' or '-mount' flag. This flag can be\ndisabled with --no-one-file-system.",
"only_matching": " Print only the matched (non-empty) parts of a matching line, with each such part on a separate\noutput line.",
"passthru": " Print both matching and non-matching lines. Another way to achieve a similar effect is by\nmodifying your pattern to match the empty string. For example, if you are searching using 'rg foo'\nthen using 'rg \"^|foo\"' instead will emit every line in every file searched, but only occurrences of\n'foo' will be highlighted. This flag enables the same behavior without needing to modify the\npattern. This overrides the --context, --after-context and --before-context flags.",
"path_separator": " Set the path separator to use when printing file paths. This defaults to your platform's path\nseparator, which is / on Unix and \\ on Windows. This flag is intended for overriding the default\nwhen the environment demands it (e.g., cygwin). A path separator is limited to a single byte.",
"pcre2": " When this flag is present, ripgrep will use the PCRE2 regex engine instead of its default regex\nengine. This is generally useful when you want to use features such as look-around or\nbackreferences. Note that PCRE2 is an optional ripgrep feature. If PCRE2 wasn't included in your\nbuild of ripgrep, then using this flag will result in ripgrep printing an error message and exiting.\nPCRE2 may also have worse user experience in some cases, since it has fewer introspection APIs than\nripgrep's default regex engine. For example, if you use a ' in a PCRE2 regex without the\n'-U/--multiline' flag, then ripgrep will silently fail to match anything instead of reporting an\nerror immediately (like it does with the default regex engine). Related flags: --no-pcre2-unicode\nThis flag can be disabled with --no-pcre2.",
"pcre2_version": " When this flag is present, ripgrep will print the version of PCRE2 in use, along with other\ninformation, and then exit. If PCRE2 is not available, then ripgrep will print an error message and\nexit with an error code.",
"pre": ' For each input FILE, search the standard output of COMMAND FILE rather than the contents of FILE.\nThis option expects the COMMAND program to either be an absolute path or to be available in your\nPATH. Either an empty string COMMAND or the \'--no-pre\' flag will disable this behavior. WARNING:\nWhen this flag is set, ripgrep will unconditionally spawn a process for every file that is searched.\nTherefore, this can incur an unnecessarily large performance penalty if you don\'t otherwise need the\nflexibility offered by this flag. One possible mitigation to this is to use the \'--pre-glob\' flag to\nlimit which files a preprocessor is run with. A preprocessor is not run when ripgrep is searching\nstdin. When searching over sets of files that may require one of several decoders as preprocessors,\nCOMMAND should be a wrapper program or script which first classifies FILE based on magic\nnumbers/content or based on the FILE name and then dispatches to an appropriate preprocessor. Each\nCOMMAND also has its standard input connected to FILE for convenience. For example, a shell script\nfor COMMAND might look like: case "$1" in *.pdf) exec pdftotext "$1" - ;; *) case $(file "$1") in\n*Zstandard*) exec pzstd -cdq ;; *) exec cat ;; esac ;; esac The above script uses `pdftotext` to\nconvert a PDF file to plain text. For all other files, the script uses the `file` utility to sniff\nthe type of the file based on its contents. If it is a compressed file in the Zstandard format, then\n`pzstd` is used to decompress the contents to stdout. This overrides the -z/--search-zip flag.',
"pretty": " This is a convenience alias for '--color always --heading --line-number'. This flag is useful when\nyou still want pretty output even if you're piping ripgrep to another program or file. For example:\n'rg -p foo | less -R'.",
"quiet": " Do not print anything to stdout. If a match is found in a file, then ripgrep will stop searching.\nThis is useful when ripgrep is used only for its exit code (which will be an error if no matches are\nfound). When --files is used, then ripgrep will stop finding files after finding the first file\nthat matches all ignore rules.",
"regex_size_limit": " The upper size limit of the compiled regex. The default limit is 10M. The argument accepts the\nsame size suffixes as allowed in the --max-filesize flag.",
"regexp": " A pattern to search for. This option can be provided multiple times, where all patterns given are\nsearched. Lines matching at least one of the provided patterns are printed. This flag can also be\nused when searching for patterns that start with a dash. For example, to search for the literal\n'-foo', you can use this flag: rg -e -foo You can also use the special '--' delimiter to indicate\nthat no more flags will be provided. Namely, the following is equivalent to the above: rg -- -foo",
"replace": " Replace every match with the text given when printing results. Neither this flag nor any other\nripgrep flag will modify your files. Capture group indices (e.g., $5) and names (e.g., $foo) are\nsupported in the replacement string. Capture group indices are numbered based on the position of the\nopening parenthesis of the group, where the leftmost such group is $1. The special $0 group\ncorresponds to the entire match. In shells such as Bash and zsh, you should wrap the pattern in\nsingle quotes instead of double quotes. Otherwise, capture group indices will be replaced by\nexpanded shell variables which will most likely be empty. To write a literal '$', use '$$'. Note\nthat the replacement by default replaces each match, and NOT the entire line. To replace the entire\nline, you should match the entire line. This flag can be used with the -o/--only-matching flag.",
"search_zip": " Search in compressed files. Currently gzip, bzip2, xz, LZ4, LZMA, Brotli and Zstd files are\nsupported. This option expects the decompression binaries to be available in your PATH. This flag\ncan be disabled with --no-search-zip.",
"smart_case": " Searches case insensitively if the pattern is all lowercase. Search case sensitively otherwise. A\npattern is considered all lowercase if both of the following rules hold: First, the pattern\ncontains at least one literal character. For example, 'a\\w' contains a literal ('a') but just '\\w'\ndoes not. Second, of the literals in the pattern, none of them are considered to be uppercase\naccording to Unicode. For example, 'foo\\pL' has no uppercase literals but 'Foo\\pL' does. This\noverrides the -s/--case-sensitive and -i/--ignore-case flags.",
"sort": " This flag enables sorting of results in ascending order. The possible values for this flag are:\nnone (Default) Do not sort results. Fastest. Can be multi-threaded. path Sort by file\npath. Always single-threaded. modified Sort by the last modified time on a file. Always single-\nthreaded. accessed Sort by the last accessed time on a file. Always single-threaded. created Sort\nby the creation time on a file. Always single-threaded. If the chosen (manually or by-default)\nsorting criteria isn't available on your system (for example, creation time is not available on ext4\nfile systems), then ripgrep will attempt to detect this, print an error and exit without searching.\nTo sort results in reverse or descending order, use the --sortr flag. Also, this flag overrides\n--sortr. Note that sorting results currently always forces ripgrep to abandon parallelism and run\nin a single thread.",
"sortr": " This flag enables sorting of results in descending order. The possible values for this flag are:\nnone (Default) Do not sort results. Fastest. Can be multi-threaded. path Sort by file\npath. Always single-threaded. modified Sort by the last modified time on a file. Always single-\nthreaded. accessed Sort by the last accessed time on a file. Always single-threaded. created Sort\nby the creation time on a file. Always single-threaded. If the chosen (manually or by-default)\nsorting criteria isn't available on your system (for example, creation time is not available on ext4\nfile systems), then ripgrep will attempt to detect this, print an error and exit without searching.\nTo sort results in ascending order, use the --sort flag. Also, this flag overrides --sort. Note\nthat sorting results currently always forces ripgrep to abandon parallelism and run in a single\nthread.",
"stats": " Print aggregate statistics about this ripgrep search. When this flag is present, ripgrep will print\nthe following stats to stdout at the end of the search: number of matched lines, number of files\nwith matches, number of files searched, and the time taken for the entire search to complete. This\nset of aggregate statistics may expand over time. Note that this flag has no effect if --files,\n--files-with-matches or files-without-match is passed. This flag can be disabled with --no-stats.",
"text": " Search binary files as if they were text. When this flag is present, ripgrep's binary file\ndetection is disabled. This means that when a binary file is searched, its contents may be printed\nif there is a match. This may cause escape codes to be printed that alter the behavior of your\nterminal. When binary file detection is enabled it is imperfect. In general, it uses a simple\nheuristic. If a NUL byte is seen during search, then the file is considered binary and search stops\n(unless this flag is present). Alternatively, if the '--binary' flag is used, then ripgrep will only\nquit when it sees a NUL byte after it sees a match (or searches the entire file). This flag can be\ndisabled with '--no-text'. It overrides the '--binary' flag.",
"threads": " The approximate number of threads to use. A value of 0 (which is the default) causes ripgrep to\nchoose the thread count using heuristics.",
"trim": " When set, all ASCII whitespace at the beginning of each line printed will be trimmed. This flag\ncan be disabled with --no-trim.",
"type": " Only search files matching TYPE. Multiple type flags may be provided. Use the type-list flag to\nlist all available types. This flag supports the special value 'all', which will behave as if\n--type was provided for every file type supported by ripgrep (including any custom file types). The\nend result is that '--type all' causes ripgrep to search in \"whitelist\" mode, where it will only\nsearch files it recognizes via its type definitions.",
"type_add": " Add a new glob for a particular file type. Only one glob can be added at a time. Multiple --type-\nadd flags can be provided. Unless --type-clear is used, globs are added to any existing globs\ndefined inside of ripgrep. Note that this MUST be passed to every invocation of ripgrep. Type\nsettings are NOT persisted. See CONFIGURATION FILES for a workaround. Example: rg --type-add\n'foo:*.foo' -tfoo PATTERN. type-add can also be used to include rules from other types with the\nspecial include directive. The include directive permits specifying one or more other type names\n(separated by a comma) that have been defined and its rules will automatically be imported into the\ntype specified. For example, to create a type called src that matches C++, Python and Markdown\nfiles, one can use: type-add 'src:include:cpp,py,md' Additional glob rules can still be added to\nthe src type by using the type-add flag again: type-add 'src:include:cpp,py,md' --type-add\n'src:*.foo' Note that type names must consist only of Unicode letters or numbers. Punctuation\ncharacters are not allowed.",
"type_clear": " ... Clear the file type globs previously defined for TYPE. This only clears the default type\ndefinitions that are found inside of ripgrep. Note that this MUST be passed to every invocation of\nripgrep. Type settings are NOT persisted. See CONFIGURATION FILES for a workaround.",
"type_list": " Show all supported file types and their corresponding globs.",
"type_not": " ... Do not search files matching TYPE. Multiple type-not flags may be provided. Use the --type-\nlist flag to list all available types.",
"unrestricted": " Reduce the level of \"smart\" searching. A single -u won't respect .gitignore (etc.) files (--no-\nignore). Two -u flags will additionally search hidden files and directories (-./--hidden). Three -u\nflags will additionally search binary files (--binary). 'rg -uuu' is roughly equivalent to 'grep\n-r'.",
"version": " Prints version information",
"vimgrep": " Show results with every match on its own line, including line numbers and column numbers. With this\noption, a line with more than one match will be printed more than once.",
"with_filename": " Display the file path for matches. This is the default when more than one file is searched. If\n--heading is enabled (the default when printing to a terminal), the file path will be shown above\nclusters of matches from each file; otherwise, the file name will be shown as a prefix for each\nmatched line. This flag overrides --no-filename.",
"word_regexp": " Only show matches surrounded by word boundaries. This is roughly equivalent to putting \x08 before and\nafter all of the search patterns. This overrides the --line-regexp flag.",
}
self.target_file_or_folder = []
self.option_targetfile = option_targetfile
self.join_parameters_dict = {}
self.same_command_multiple_times = {"--regexp": ""}
self.separador_for_multiple_arguments = "Ç"
self.self_added_arguments = []
self.last_command_line_called = []
def add_python_variable_instead_of_file(self, variable: [bytes, str]):
if isinstance(variable, str):
variable = variable.encode()
self.target_file_or_folder.append(variable)
return self
def add_target_file_or_folder(self, target_file_or_folder: Union[str, list]):
if isinstance(target_file_or_folder, str):
target_file_or_folder = [target_file_or_folder]
self.target_file_or_folder.extend(target_file_or_folder)
return self
def reset_options(self):
for key in list(self.execute_dict.keys()):
self.execute_dict[key] = False
self.self_added_arguments = []
return self
def print_options_to_screen(self):
for help, exe in zip(self.helpdict.items(), self.execute_dict.items()):
key_h, item_h = help
key_e, item_e = exe
print(f"""Parameter:\t\t\t{key_e} {key_h}""")
print(f"""Current Settings:\t\t{item_e} """)
print(f"""Information:\t\t{item_h}""")
print(
"---------------------------------------------------------------------------------------------"
)
print(f"""Self Added Arguments:\t\tf{self.self_added_arguments}""")
return self
def run(
self,
capture_output: bool = True,
save_output_with_shell: Union[None, str] = None,
):
self.last_command_line_called = []
regexlist = []
add_to_search = [
(
re.sub(rf"{self.separador_for_multiple_arguments}\d*$", "", x[0]),
str(x[1]),
x[1],
)
for x in self.execute_dict.items()
if x[1] is not False
]
add_to_search_list = []
for key, item, real_value in add_to_search:
if isinstance(real_value, bool):
add_to_search_list.append([key])
else:
if key in self.join_parameters_dict:
add_to_search_list.append([f"{key}{item}"])
else:
add_to_search_list.append([key, item])
regexlist.extend(add_to_search_list)
regexlist = self.necessary_beginning + regexlist + self.self_added_arguments
regexlist = PyRipGREP.flatten_iter(regexlist)
if self.option_targetfile is not None:
regexlist.append(self.option_targetfile)
if self.target_file_or_folder:
if isinstance(self.target_file_or_folder[0], str):
regexlist.extend(self.target_file_or_folder)
else:
f = tempfile()
f.write(self.target_file_or_folder[0])
f.seek(0)
ergebnis = subprocess.run(regexlist, stdin=f, capture_output=True)
print(ergebnis.args)
f.close()
self.last_command_line_called = regexlist.copy()
return ergebnis
if save_output_with_shell is not None:
regexlist.append(">>")
regexlist.append(save_output_with_shell)
ergebnis = subprocess.run(
regexlist, capture_output=capture_output, shell=True
)
else:
ergebnis = subprocess.run(regexlist, capture_output=capture_output)
self.last_command_line_called = regexlist.copy()
return ergebnis
def add_own_parameter_or_option(self, values):
if not isinstance(values, (list, tuple)):
values = [values]
values = self.flatten_iter(values)
self.self_added_arguments.extend(values)
return self
@staticmethod
def _delete_duplicates_from_nested_list(nestedlist):
tempstringlist = {}
for ergi in nestedlist:
tempstringlist[str(ergi)] = ergi
endliste = [tempstringlist[key] for key in tempstringlist.keys()]
return endliste.copy()
@staticmethod
def flatten_iter(iterable):
def iter_flatten(iterable):
it = iter(iterable)
for e in it:
if isinstance(e, (list, tuple)):
for f in iter_flatten(e):
yield f
else:
yield e
a = [
i if not isinstance(i, (str, int, float)) else [i]
for i in iter_flatten(iterable)
]
a = [i for i in iter_flatten(a)]
return a
def _handle_multiple_times_same_flag(self, key_to_check, value_to_set):
are_there_more = True
startvalue = 0
keytocheck = ""
while are_there_more:
keytocheck = (
f"{key_to_check}"
+ self.separador_for_multiple_arguments
+ str(startvalue)
)
if not keytocheck in self.execute_dict:
are_there_more = False
else:
if isinstance(value_to_set, bool):
if value_to_set is False:
self.execute_dict[keytocheck] = value_to_set
startvalue = startvalue + 1
if keytocheck not in self.execute_dict:
if isinstance(value_to_set, bool):
if value_to_set is False:
return
self.execute_dict[keytocheck] = value_to_set
def _print_option_activate_warning(self):
pass
def after_context(
self, option=None, activated=True, multi_allowed=False, get_help=False
):
"""Show NUM lines after each match. This overrides the --context and --passthru flags."""
if get_help:
print(self.helpdict["after_context"])
return self
varformulti = ""
if not activated:
self.execute_dict["--after-context"] = False
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--after-context", value_to_set=False
)
return self
if isinstance(option, bool):
self._print_option_activate_warning()
self.execute_dict["--after-context"] = True
varformulti = True
elif option is not None and activated:
if self.execute_dict["--after-context"] is False and not multi_allowed:
self.execute_dict["--after-context"] = option
varformulti = option
else:
self.execute_dict["--after-context"] = True
varformulti = True
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--after-context", value_to_set=varformulti
)
return self
def auto_hybrid_regex(
self, option=None, activated=True, multi_allowed=False, get_help=False
):
"""DEPRECATED. Use --engine instead. When this flag is used, ripgrep will dynamically choose between
supported regex engines depending on the features used in a pattern. When ripgrep chooses a regex
engine, it applies that choice for every regex provided to ripgrep (e.g., via multiple -e/--regexp
or -f/--file flags). As an example of how this flag might behave, ripgrep will attempt to use its
default finite automata based regex engine whenever the pattern can be successfully compiled with
that regex engine. If PCRE2 is enabled and if the pattern given could not be compiled with the
default regex engine, then PCRE2 will be automatically used for searching. If PCRE2 isn't available,
then this flag has no effect because there is only one regex engine to choose from. In the future,
ripgrep may adjust its heuristics for how it decides which regex engine to use. In general, the
heuristics will be limited to a static analysis of the patterns, and not to any specific runtime
behavior observed while searching files. The primary downside of using this flag is that it may not
always be obvious which regex engine ripgrep uses, and thus, the match semantics or performance
profile of ripgrep may subtly and unexpectedly change. However, in many cases, all regex engines
will agree on what constitutes a match and it can be nice to transparently support more advanced
regex features like look-around and backreferences without explicitly needing to enable them. This
flag can be disabled with --no-auto-hybrid-regex."""
if get_help:
print(self.helpdict["auto_hybrid_regex"])
return self
varformulti = ""
if not activated:
self.execute_dict["--auto-hybrid-regex"] = False
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--auto-hybrid-regex", value_to_set=False
)
return self
if isinstance(option, bool):
self._print_option_activate_warning()
self.execute_dict["--auto-hybrid-regex"] = True
varformulti = True
elif option is not None and activated:
if self.execute_dict["--auto-hybrid-regex"] is False and not multi_allowed:
self.execute_dict["--auto-hybrid-regex"] = option
varformulti = option
else:
self.execute_dict["--auto-hybrid-regex"] = True
varformulti = True
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--auto-hybrid-regex", value_to_set=varformulti
)
return self
def before_context(
self, option=None, activated=True, multi_allowed=False, get_help=False
):
"""Show NUM lines before each match. This overrides the --context and --passthru flags."""
if get_help:
print(self.helpdict["before_context"])
return self
varformulti = ""
if not activated:
self.execute_dict["--before-context"] = False
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--before-context", value_to_set=False
)
return self
if isinstance(option, bool):
self._print_option_activate_warning()
self.execute_dict["--before-context"] = True
varformulti = True
elif option is not None and activated:
if self.execute_dict["--before-context"] is False and not multi_allowed:
self.execute_dict["--before-context"] = option
varformulti = option
else:
self.execute_dict["--before-context"] = True
varformulti = True
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--before-context", value_to_set=varformulti
)
return self
def binary(self, option=None, activated=True, multi_allowed=False, get_help=False):
"""Enabling this flag will cause ripgrep to search binary files. By default, ripgrep attempts to
automatically skip binary files in order to improve the relevance of results and make the search
faster. Binary files are heuristically detected based on whether they contain a NUL byte or not. By
default (without this flag set), once a NUL byte is seen, ripgrep will stop searching the file.
Usually, NUL bytes occur in the beginning of most binary files. If a NUL byte occurs after a match,
then ripgrep will still stop searching the rest of the file, but a warning will be printed. In
contrast, when this flag is provided, ripgrep will continue searching a file even if a NUL byte is
found. In particular, if a NUL byte is found then ripgrep will continue searching until either a
match is found or the end of the file is reached, whichever comes sooner. If a match is found, then
ripgrep will stop and print a warning saying that the search stopped prematurely. If you want
ripgrep to search a file without any special NUL byte handling at all (and potentially print binary
data to stdout), then you should use the '-a/--text' flag. The '--binary' flag is a flag for
controlling ripgrep's automatic filtering mechanism. As such, it does not need to be used when
searching a file explicitly or when searching stdin. That is, it is only applicable when recursively
searching a directory. Note that when the '-u/--unrestricted' flag is provided for a third time,
then this flag is automatically enabled. This flag can be disabled with '--no-binary'. It overrides
the '-a/--text' flag."""
if get_help:
print(self.helpdict["binary"])
return self
varformulti = ""
if not activated:
self.execute_dict["--binary"] = False
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--binary", value_to_set=False
)
return self
if isinstance(option, bool):
self._print_option_activate_warning()
self.execute_dict["--binary"] = True
varformulti = True
elif option is not None and activated:
if self.execute_dict["--binary"] is False and not multi_allowed:
self.execute_dict["--binary"] = option
varformulti = option
else:
self.execute_dict["--binary"] = True
varformulti = True
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--binary", value_to_set=varformulti
)
return self
def block_buffered(
self, option=None, activated=True, multi_allowed=False, get_help=False
):
"""When enabled, ripgrep will use block buffering. That is, whenever a matching line is found, it will
be written to an in-memory buffer and will not be written to stdout until the buffer reaches a
certain size. This is the default when ripgrep's stdout is redirected to a pipeline or a file. When
ripgrep's stdout is connected to a terminal, line buffering will be used. Forcing block buffering
can be useful when dumping a large amount of contents to a terminal. Forceful block buffering can
be disabled with --no-block-buffered. Note that using --no-block-buffered causes ripgrep to revert
to its default behavior of automatically detecting the buffering strategy. To force line buffering,
use the --line-buffered flag."""
if get_help:
print(self.helpdict["block_buffered"])
return self
varformulti = ""
if not activated:
self.execute_dict["--block-buffered"] = False
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--block-buffered", value_to_set=False
)
return self
if isinstance(option, bool):
self._print_option_activate_warning()
self.execute_dict["--block-buffered"] = True
varformulti = True
elif option is not None and activated:
if self.execute_dict["--block-buffered"] is False and not multi_allowed:
self.execute_dict["--block-buffered"] = option
varformulti = option
else:
self.execute_dict["--block-buffered"] = True
varformulti = True
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--block-buffered", value_to_set=varformulti
)
return self
def byte_offset(
self, option=None, activated=True, multi_allowed=False, get_help=False
):
"""Print the 0-based byte offset within the input file before each line of output. If -o (--only-
matching) is specified, print the offset of the matching part itself. If ripgrep does transcoding,
then the byte offset is in terms of the the result of transcoding and not the original data. This
applies similarly to another transformation on the source, such as decompression or a --pre filter.
Note that when the PCRE2 regex engine is used, then UTF-8 transcoding is done by default.
"""
if get_help:
print(self.helpdict["byte_offset"])
return self
varformulti = ""
if not activated:
self.execute_dict["--byte-offset"] = False
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--byte-offset", value_to_set=False
)
return self
if isinstance(option, bool):
self._print_option_activate_warning()
self.execute_dict["--byte-offset"] = True
varformulti = True
elif option is not None and activated:
if self.execute_dict["--byte-offset"] is False and not multi_allowed:
self.execute_dict["--byte-offset"] = option
varformulti = option
else:
self.execute_dict["--byte-offset"] = True
varformulti = True
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--byte-offset", value_to_set=varformulti
)
return self
def case_sensitive(
self, option=None, activated=True, multi_allowed=False, get_help=False
):
"""Search case sensitively. This overrides the -i/--ignore-case and -S/--smart-case flags."""
if get_help:
print(self.helpdict["case_sensitive"])
return self
varformulti = ""
if not activated:
self.execute_dict["--case-sensitive"] = False
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--case-sensitive", value_to_set=False
)
return self
if isinstance(option, bool):
self._print_option_activate_warning()
self.execute_dict["--case-sensitive"] = True
varformulti = True
elif option is not None and activated:
if self.execute_dict["--case-sensitive"] is False and not multi_allowed:
self.execute_dict["--case-sensitive"] = option
varformulti = option
else:
self.execute_dict["--case-sensitive"] = True
varformulti = True
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--case-sensitive", value_to_set=varformulti
)
return self
def color(self, option=None, activated=True, multi_allowed=False, get_help=False):
"""This flag controls when to use colors. The default setting is 'auto', which means ripgrep will try
to guess when to use colors. For example, if ripgrep is printing to a terminal, then it will use
colors, but if it is redirected to a file or a pipe, then it will suppress color output. ripgrep
will suppress color output in some other circumstances as well. For example, if the TERM environment
search_in is not set or set to 'dumb', then ripgrep will not use colors. The possible values for
this flag are: never Colors will never be used. auto The default. ripgrep tries to be smart.
always Colors will always be used regardless of where output is sent. ansi Like 'always', but
emits ANSI escapes (even in a Windows console). When the --vimgrep flag is given to ripgrep, then
the default value for the color flag changes to 'never'."""
if get_help:
print(self.helpdict["color"])
return self
varformulti = ""
if not activated:
self.execute_dict["--color"] = False
if multi_allowed:
self._handle_multiple_times_same_flag(
key_to_check="--color", value_to_set=False
)