You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
grep and git grep support printing context lines around matches. -C 3 prints three lines of context before and after each match; -A 3 prints three lines after, and -B 3 prints three lines before.
I'd love to have the same functionality in ast-grep's sg run: sg -C 3 -p xyz.
As with grep and git grep, context lines should be printed slightly differently than matching lines. When printing context lines, grep and git grep print filename: before each matching line but filename- before each non-matching context line, and print a -- between matches. If a line in the context also matches the pattern, they print that line as filename: as well, and extend the context. For instance, for git grep -C3 matching:
...
--
file- context line
file- context line
file- context line
file: matching line
file- context line
file: another matching line
file- context line
file- context line
file- context line
--
...
💻 Use Cases
Having context makes it easier to skim through a series of matches. I use these options quite frequently with grep and git grep. Not having them in sg means I may need to check each match one by one, such as in an editor, rather than skimming through a series of them and only looking at ones with relevant context.
The text was updated successfully, but these errors were encountered:
⭐ Suggestion
grepandgit grepsupport printing context lines around matches.-C 3prints three lines of context before and after each match;-A 3prints three lines after, and-B 3prints three lines before.I'd love to have the same functionality in ast-grep's
sg run:sg -C 3 -p xyz.As with
grepandgit grep, context lines should be printed slightly differently than matching lines. When printing context lines,grepandgit grepprintfilename:before each matching line butfilename-before each non-matching context line, and print a--between matches. If a line in the context also matches the pattern, they print that line asfilename:as well, and extend the context. For instance, forgit grep -C3 matching:💻 Use Cases
Having context makes it easier to skim through a series of matches. I use these options quite frequently with
grepandgit grep. Not having them insgmeans I may need to check each match one by one, such as in an editor, rather than skimming through a series of them and only looking at ones with relevant context.The text was updated successfully, but these errors were encountered: