CLI and Interactive TUI tool written in Go to search and replace text in files recursively with backup/restore functionality.
PhotonSR is a powerful and user-friendly text replacement tool that allows you to:
- Replace text patterns in files across directories using command-line arguments.
- NEW: Use an interactive Text User Interface (TUI) wizard for a guided experience.
- Create automatic
.bak
backups before modifying files. - Restore original files from these backups.
- Clean up (delete) all backup files in a directory.
The TUI mode is particularly helpful for users who prefer a step-by-step process over typing out all command-line flags.
- ๐ Text Replacement - Replace strings in all matching files.
- ๐ง Interactive Wizard Mode (TUI) - A user-friendly, step-by-step terminal interface for all operations (built with Bubble Tea).
- ๐พ Backup System - Auto-create
.bak
files before modification. - โฎ๏ธ Restore System - Revert files from
.bak
backups. - ๐งน Clean Backups - Delete all
.bak
files. - ๐ Pattern Matching - Target files using wildcard patterns (e.g.,
*.txt
,src/**/*.go
). - โ Input Validation - Enhanced checks for inputs like directory paths and file patterns in TUI mode.
- ๐ก๏ธ Error Handling - Improved feedback for both CLI and TUI modes.
curl
orwget
installed on your system.tar
installed (for extracting the downloaded archive).- For standard Linux/macOS systems, you might need
sudo
privileges if installing to a system directory like/usr/local/bin
.
You can install PhotonSR with a single command using either curl
or wget
. 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/arwahdevops/PhotonSR/main/install.sh)"
Using wget
:
sh -c "$(wget -qO- https://raw.githubusercontent.com/arwahdevops/PhotonSR/main/install.sh)"
After installation, you might need to open a new terminal session or source your shell's configuration file (e.g., source ~/.bashrc
, source ~/.zshrc
) for the photonsr
command to be available.
If you prefer to build from source:
-
Prerequisites:
- Go 1.24.2 or newer (update this if your
go.mod
specifies a newer version). - Git
- Go 1.24.2 or newer (update this if your
-
Clone and Build:
# Clone repository git clone https://github.com/arwahdevops/PhotonSR.git cd PhotonSR # Build go build -o photonsr ./cmd
-
Install Manually: Move the compiled
photonsr
binary to a directory in yourPATH
.# Example: install to /usr/local/bin (may require sudo) sudo mv photonsr /usr/local/bin/ # Or for Termux: # mv photonsr $PREFIX/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 the steps for any operation.
To start the wizard mode, simply run:
photonsr
Or explicitly:
photonsr -wizard
The wizard will prompt you for the action (Replace, Restore, Clean), target directory, text, patterns, and other necessary options.
Use command-line flags for scripting or if you prefer direct commands.
photonsr [OPTIONS] -old "OLD_TEXT" -new "NEW_TEXT"
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 (e.g., *.txt , main.* ) |
Replace | |
-old |
Text to replace (required for replace operation) | Replace | |
-new |
Replacement text (required for replace operation) | Replace | |
-backup |
Create .bak backup files before modification |
Replace | |
-restore |
Restore files from .bak backups |
Restore | |
-clean |
Delete all .bak files in the target directory |
Clean | |
-version |
Show application version and exit. | (Global) |
Note: If photonsr
is run without any operation flags (-old
, -restore
, -clean
) and -wizard
is not specified, it will default to launching the Wizard Mode.
Replaces "foo" with "bar" in all .md
files within the docs
directory.
photonsr -dir docs -pattern "*.md" -old "foo" -new "bar"
Replaces "http://" with "https://" in all files (default pattern *
) within the src
directory, creating backups first.
photonsr -dir src -old "http://" -new "https://" -backup
Restores original files from .bak
files in the project
directory.
photonsr -dir project -restore
Deletes all .bak
files from the data
directory.
photonsr -dir data -clean
For any of the above operations, or if you're unsure about the flags, simply run:
photonsr
...and follow the on-screen prompts.
- Backup Safety:
- Backup files (e.g.,
filename.txt.bak
) are created in the same directory as the original file. - Original file permissions are preserved on both the modified file and the backup file.
- Backup files (e.g.,
- Pattern Matching:
- Uses standard Go
filepath.Match
glob patterns:*
matches any sequence of non-separator characters.?
matches any single non-separator character.[set]
matches any one character in set.[^set]
matches any one character not in set.- For more complex needs, consider tools with regex support.
- Uses standard Go
- Case Sensitivity:
- Text replacement is case-sensitive by default. "Foo" will not match "foo".
- Safety First:
- Always double-check your replacement text (
-old
and-new
), target directory (-dir
), and file patterns (-pattern
) before execution, especially in CLI mode. - It is highly recommended to use the
-backup
flag (or confirm backup creation in wizard mode) for critical operations. Test on non-critical data first if unsure.
- Always double-check your replacement text (
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 issues page. (Consider adding a CONTRIBUTING.md if you have specific guidelines)
- Bubble Tea and the Charmbracelet ecosystem for making TUI development in Go delightful.