CLI and Interactive TUI tool written in Go to search and replace text in files recursively with backup/restore functionality.
PhotonSR is a powerful, memory-efficient, and user-friendly text replacement tool that allows you to:
- Replace text patterns or regular expressions in files across directories.
- Use an interactive Text User Interface (TUI) wizard for a guided experience.
- Create automatic
.bakbackups before modifying files. - Restore original files from these backups.
- Clean up (delete) all backup files in a directory.
- Simulate changes with a
dry-runmode before committing.
The TUI mode is particularly helpful for users who prefer a step-by-step process, while the powerful CLI flags offer full control for scripting and automation.
- π Text & Regex Replacement - Replace literal strings or use the power of Regular Expressions.
- π§ Interactive Wizard Mode (TUI) - A user-friendly, step-by-step terminal interface for all operations (built with Bubble Tea).
- π¨ Large File Support - Memory-efficient streaming design handles large files with ease.
- π‘οΈ Binary File Detection - Automatically detects and skips binary files to prevent corruption, with a
--forceoverride. - π Dry Run Mode - Preview which files will be changed without making any modifications.
- πΎ Backup & Restore System - Auto-create
.bakfiles before modification and restore them if needed. - π§Ή Clean Backups - A simple command to delete all
.bakfiles. - π Pattern Matching - Target files using wildcard patterns (e.g.,
*.txt,src/**/*.go). β οΈ Interactive Safety Prompts - The CLI will ask for confirmation before performing destructive operations.
curlorwgetinstalled on your system.tarinstalled (for extracting the downloaded archive).
You can install PhotonSR with a single command. The script will automatically detect your OS and architecture, download the latest version, and install it to a standard location (e.g., /usr/local/bin or $PREFIX/bin on Termux).
Using curl:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/atomiclogic/PhotonSR/main/install.sh)"Using wget:
sh -c "$(wget -qO- https://raw.githubusercontent.com/atomiclogic/PhotonSR/main/install.sh)"After installation, you might need to open a new terminal session for the photonsr command to be available.
- Prerequisites: Go 1.24.2+ and Git.
- Clone and Build:
git clone https://github.com/arwahdevops/PhotonSR.git cd PhotonSR go build -o photonsr ./cmd - Install Manually: Move the
photonsrbinary to a directory in yourPATH(e.g.,sudo mv photonsr /usr/local/bin/).
PhotonSR can be run in two modes: CLI Mode (using command-line flags) or Wizard Mode (interactive TUI).
This is the recommended mode for ease of use. It will guide you through all options, including Regex, Dry Run, and more.
To start the wizard mode, simply run:
photonsrUse command-line flags for scripting or if you prefer direct commands.
photonsr [OPTIONS] -old "SEARCH_TERM" -new "REPLACEMENT"
photonsr [OPTIONS] -restore
photonsr [OPTIONS] -clean| Flag | Alias | Description | Applicable To |
|---|---|---|---|
-wizard |
Run in interactive wizard (TUI) mode. | (Mode selection) | |
-dir |
Target directory (default: current directory .) |
All operations | |
-pattern |
Filename pattern to target (e.g., *.txt, main.*) |
Replace | |
-old |
Text or Regex pattern to search for. | Replace | |
-new |
Text to replace the matched search term with. | Replace | |
-regex |
Treat the -old pattern as a regular expression. |
Replace | |
-backup |
Create .bak backup files before modification. |
Replace | |
-dry-run |
Simulate the operation and show what would change without modifying files. | Replace | |
-force |
Force processing of files that appear to be binary. | Replace | |
-restore |
Restore files from .bak backups. |
Restore | |
-clean |
Delete all .bak files in the target directory. |
Clean | |
-y |
Skip interactive confirmation prompts for destructive operations. | All CLI Ops | |
-version |
Show application version and exit. | (Global) |
Replaces "foo" with "bar" in all .md files, creating backups first.
photonsr -dir ./docs -pattern "*.md" -old "foo" -new "bar" -backupReplaces email addresses with a placeholder in all .log files using a regex pattern.
photonsr -dir ./logs -pattern "*.log" -regex -old "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}" -new "[REDACTED]"See which files would be modified if you replaced "http" with "https", without actually changing them.
photonsr -dir ./src -old "http://" -new "https://" -dry-runRestores original files from backups. The tool will ask for confirmation first.
photonsr -dir ./project -restore
> This will overwrite current files with their .bak versions. Are you sure? [y/N]: yTo skip the confirmation prompt in a script, use the -y flag:
photonsr -dir ./project -restore -y- Safety First: The CLI will now prompt for confirmation before executing destructive operations (
restore,clean, orreplacewithout-backup). Use the-yflag to bypass this in scripts. - Binary Files: The tool automatically detects and skips binary files to prevent corruption. If you need to run on all files regardless of content, use the
--forceflag. - Regex Usage: When using the
-regexflag, ensure your-oldpattern is a valid Go regular expression. The replacement text in-newis treated as a literal string, but can use capture group variables like$1,$2, etc. - Large Files: Thanks to its streaming architecture, PhotonSR can handle very large files without consuming excessive memory.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Bubble Tea and the Charmbracelet ecosystem for making TUI development in Go delightful.