Skill站外收录 @skilllib/skill-2014279409287507970
skills
执行跨文件的多模式搜索替换与重命名操作,支持同时处理代码内容、文件及目录名称的批量重构,在一次操作中完成大小写敏感的标识符转换、正则匹配替换和安全的原子化变更,适用于大规模项目重命名和模式化文本迁移。
效率工具 AI 技能
Skills.MD
# Repren - Multi-Pattern Search and Replace
> **Full documentation: Run `uvx repren@latest --docs` for all options, flags, and
> advanced usage.**
Multi-pattern search/replace tool for bulk refactoring with simultaneous replacements,
file/directory renaming, and case-preserving transformations.
## Quick Start
**Always start with dry-run** to preview changes:
```bash
uvx repren@latest --from='old_name' --to='new_name' --full --dry-run src/
```
Then execute if output looks correct:
```bash
uvx repren@latest --from='old_name' --to='new_name' --full src/
```
## When to Use Repren
**Use repren for:**
- Large-scale code refactoring (renaming across many files)
- Simultaneous multi-pattern replacements
- File and directory renaming based on content patterns
- Case-preserving identifier transformations
- Operations requiring dry-run validation and backups
- Swapping or circular renames (foo↔bar)
**Don’t use repren for:**
- Single-file small edits or replacements (use Edit tool instead)
- Language-aware semantic refactoring (use AST tools like ast-grep, ts-morph)
- Operations requiring precise line-by-line control (use Edit tool)
## Core Features
### Simultaneous Multi-Pattern Replacement
Create a patterns file with tab-separated pairs:
```
old_function new_function
OldClass NewClass
CONSTANT_OLD CONSTANT_NEW
```
Apply all patterns at once:
```bash
uvx repren@latest --patterns=patterns.txt --full src/
```
Repren handles overlapping patterns intelligently: you can swap names (foo↔bar) in a
single pass.
### Case-Preserving Transformations
Handle all case variants automatically:
```bash
uvx repren@latest --from='my_var' --to='my_function' --preserve-case --full src/
```
Transforms: `my_var`→`my_function`, `myVar`→`myFunction`, `MyVar`→`MyFunction`,
`MY_VAR`→`MY_FUNCTION`.
### File and Directory Renaming
With `--full`, in addition to searching and replacing content, repren will rename files
and directories matching the patterns.
```bash
uvx repren@latest --from='old_module' --to='new_module' --full src/
```
Renames files and directories, creating parent directories as needed. Files never
clobber: numeric suffixes are added if conflicts arise.
### Regex Patterns with Capture Groups
Use full Python regex syntax with backreferences:
```bash
uvx repren@latest --from='figure ([0-9]+)' --to='Figure \1' --full docs/
```
Pattern file example:
```
def (\w+)\(self\) def \1(self, context)
class Old(\w+) class New\1
```
## Safety and Backup Management
### Atomic Operations with Backups
All modifications create `.orig` backup files automatically. Original files never
truncated on errors.
### Dry Run
**Always preview changes first:**
```bash
uvx repren@latest --dry-run --patterns=patterns.txt --full mydir/
```
Shows exactly what would change without modifying files.
### Undo Changes
Restore from backups if needed:
```bash
uvx repren@latest --undo --from='old' --to='new' --full src/
```
### Clean Backups
Remove backups when satisfied:
```bash
uvx repren@latest --clean-backups src/
```
## Common Workflows
### Large Codebase Refactoring
1. Preview changes:
```bash
uvx repren@latest --from='OldName' --to='NewName' --preserve-case --word-breaks --full --dry-run src/
```
2. Execute if output looks correct:
```bash
uvx repren@latest --from='OldName' --to='NewName' --preserve-case --word-breaks --full src/
```
3. Review changes, test, then clean backups:
```bash
uvx repren@latest --clean-backups src/
```
### Filtering Files
Include only specific file types:
```bash
uvx repren@latest --patterns=patterns.txt --include='.*\.(py|pyi)$' --full src/
```
Exclude directories:
```bash
uvx repren@latest --patterns=patterns.txt --exclude='tests|node_modules|__pycache__' --full src/
```
### Word Boundaries
Match only at word boundaries (safer for variable names):
```bash
uvx repren@latest --from='var' --to='variable' --word-breaks --full src/
```
### Literal Patterns
Treat patterns as literal strings (not regex):
```bash
uvx repren@latest --from='file.txt' --to='data.txt' --literal --full docs/
```
### Multi-Line Patterns
Process entire files at once for patterns spanning lines:
```bash
uvx repren@latest --patterns=patterns.txt --at-once --full src/
```
## Machine-Readable Output
Use JSON format for programmatic processing:
```bash
uvx repren@latest --format=json --from='old' --to='new' --full src/
```
Returns structured data about all changes made.
## Key Flags
Most important flags (run `uvx repren@latest --docs` for complete list):
| Flag | Purpose |
| --- | --- |
| `--full` | Apply to files AND rename them (not just stdin/stdout) |
| `--dry-run`, `-n` | Preview without modifying |
| `--patterns=FILE` | Use multi-pattern file instead of single --from/--to |
| `--preserve-case` | Handle camelCase, snake_case, PascalCase, UPPER_CASE variants |
| `--word-breaks` | Match only at word boundaries (safer for identifiers) |
| `--at-once` | Process entire file (needed for multi-line patterns) |
| `--format=json` | Machine-parseable output for scripts |
| `--undo` | Restore from .orig backups |
| `--clean-backups` | Remove backup files |
## Pattern File Format
Tab-separated pattern/replacement pairs:
```
pattern<TAB>replacement
another<TAB>replacement
# Comments start with #
```
Supports regex with capture groups `(\w+)` and backreferences `\1`, `\2`. First match
wins for overlaps.
## Notes
- All pattern matching uses Python regex syntax
- Replacements are line-by-line by default, use `--at-once` for full-file
- Multiple patterns matched first, then all replaced (enables swaps)
- Binary files supported (patterns specified as strings, data handled as bytes)
- File permissions preserved
- Operations are atomic - temp files used, then renamed
- Default excludes hidden files (starting with `.`), customizable with `--exclude`
- Backup files (`.orig` by default) always ignored in recursive operations
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「skills」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次