Linux command
srgn 命令
文本
涉及管道、覆盖或删除,执行前请先确认路径和参数。
常用示例
Replace matching text
echo 'Hello World!' | srgn '[wW]orld' -- 'there'
Convert piped input to uppercase
echo 'hello' | srgn --upper '.*'
Delete matching characters
echo 'Hello World!' | srgn --delete '[!]'
Squeeze repeated characters
echo 'Helloooo Woooorld!!!' | srgn --squeeze '(o|!)'
Search within Python class definitions
srgn --python 'class' '[age]'
Convert to lowercase within Rust strings only
srgn --rust 'string' --lower '.*'
说明
srgn is a grep-like tool that understands source code syntax via tree-sitter and allows manipulation in addition to search. It combines capabilities of tr, sed, and ripgrep with language grammar awareness, supporting Python, Rust, Go, TypeScript, C, C#, and HCL. It can perform bulk file edits, case transformations, and regex replacements scoped to specific syntactic constructs. Actions are composable and applied in a fixed order regardless of flag order. Replacement (positional, after --) is applied first, then flags like --upper, --lower, --delete, and --squeeze are applied in sequence.
参数
- --upper
- Convert matched text to uppercase
- --lower
- Convert matched text to lowercase
- --delete
- Delete matched text
- --squeeze
- Squeeze consecutive repeated characters into single occurrences
- --python _QUERY_
- Scope to Python syntax nodes (e.g., class, function, string)
- --rust _QUERY_
- Scope to Rust syntax nodes
- --go _QUERY_
- Scope to Go syntax nodes
- --typescript _QUERY_
- Scope to TypeScript syntax nodes
- --c _QUERY_
- Scope to C syntax nodes
- --csharp _QUERY_
- Scope to C# syntax nodes
- --hcl _QUERY_
- Scope to HCL syntax nodes
- --glob _PATTERN_
- Process files matching glob pattern
FAQ
What is the srgn command used for?
srgn is a grep-like tool that understands source code syntax via tree-sitter and allows manipulation in addition to search. It combines capabilities of tr, sed, and ripgrep with language grammar awareness, supporting Python, Rust, Go, TypeScript, C, C#, and HCL. It can perform bulk file edits, case transformations, and regex replacements scoped to specific syntactic constructs. Actions are composable and applied in a fixed order regardless of flag order. Replacement (positional, after --) is applied first, then flags like --upper, --lower, --delete, and --squeeze are applied in sequence.
How do I run a basic srgn example?
Run `echo 'Hello World!' | srgn '[wW]orld' -- 'there'` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --upper do in srgn?
Convert matched text to uppercase