Repository navigation
Examples
Basics sr replace "old_api" "new_api" -p '.py' sr replace "old" "new" # every text file below cwd sr replace "old" "new" -C ~/projects/api # another directory sr replace "old" "new" --file src/a.py --file src/b.py git ls-files '.py' | sr replace "old" "new" --files-from -
Looking before leaping sr find "TODO" -p '.py' sr find "TODO" --count sr find "TODO" -l # file names only sr find "TODO" -A 2 -B 2 # with context sr diff "old" "new" -p '.md' sr replace "old" "new" --dry-run sr replace "old" "new" --dry-run --json | jq '.totals'
Regular expressions sr replace 'version = "(\d+.\d+)"' 'version = "\1.post0"' --regex -p 'setup.py' sr replace 'import old\b' 'import new' --regex -p '.py' sr replace [[:digit:]]{3}-:digit:{4}' 'XXX-XXXX' --ere sr replace '(?<=password=)\S+' 'changeme' --pcre -p '.env' --hidden sr replace "cat" "dog" -w # whole words only sr replace "Warning" "Notice" -i
Scoped edits sr replace "old" "new" --line-range 1-30 -p 'header*' sr replace "TODO" "DONE" --max-count 1 sr replace "a" "b" --no-global # first per line sr replace "a" "b" --include 'src/**/.py' --exclude 'src/vendor/' sr replace "a" "b" --max-depth 2 --hidden sr replace "a" "b" --newer-than 7d
Safety and review sr replace "old" "new" --interactive sr replace "old" "new" --write=dir --output-dir out sr replace "old" "new" --confirm-threshold 5 sr sessions sr diff --session latest sr rollback latest --dry-run sr rollback 9f3a1c --file src/app.py sr sessions prune --keep 10 --keep-age 30d
Renaming sr rename ".txt" ".md" -p '.txt' sr rename --regex '^(.).jpeg$' '\1.jpg' sr replace "MyClass" "YourClass" --rename -p '*.py'
Encodings and line endings sr replace "old" "new" --encoding cp1251 -p '.txt' sr replace "old" "new" --encoding utf-16 --hidden sr replace "\r\n" "\n" --multiline -p '.sh' # CRLF → LF sr replace "old" "new" --line-endings lf -p '*.py'
Automation sr replace "old" "new" --yes --json --no-update-check > report.json sr find "old" --porcelain | cut -d: -f1 | sort -u sr replace "1.2.3" "1.2.4" -p 'package.json' -p 'pyproject.toml' --no-backup SR_IGNORE_CASE=true sr replace "warning" "notice" -p '*.md'
Real-world migrations
sr replace '"version": "6.1.0"' '"version": "7.0.0"' -p package.json
sr replace "from app.utils import" "from core.utils import" --gitignore
sr replace "legacy_call(" "modern_call(" -p '*.py' && sr find "legacy_call"
Страница сгенерирована из встроенной справки sr 7.0.1 (sr help <topic>).
Первоисточник — sr/help_system.py; он же питает man sr и sr help --all.
Если страница и вывод sr help расходятся, верить нужно sr help: он всегда
соответствует установленной версии.