3 unstable releases
0.2.0 | Oct 18, 2024 |
---|---|
0.1.1 | Sep 16, 2024 |
0.1.0 | Sep 16, 2024 |
#313 in Filesystem
16KB
345 lines
Replacer
A BLAZINGLy FAST CLI tool written in Rust to replace strings in files or stdin, recursively and quickly.
Features
- Replace text in files or directories recursively
- Process input from stdin
- Case-sensitive or case-insensitive replacements
- Ignore specific files or directories
- Use glob patterns for ignoring files
- Override ignore settings
- Specify replacement pairs via CLI or config file
Installation
cargo install replacer-cli
Usage
replacer [FLAGS] [OPTIONS] [TARGET]
If no TARGET is specified, Replacer will process input from stdin and write to stdout.
Flags
-s, --case-insensitive
: Make replacements case-insensitive-h, --help
: Print help information-V, --version
: Print version information
Options
-c, --config <FILE>
: Path to the config file (default: "replacer.config.toml")-i, --ignore <PATHS>...
: Ignore directories or files-n, --no-ignore <PATHS>...
: Don't ignore directories or files (overrides ignore config)-p, --pair <KEY=VALUE>
: Additional replacement pairs (format: key=value)
Arguments
<TARGET>
: Path to the target file or directory (omit for stdin)
Configuration File
You can use a configuration file (default: replacer.config.toml
) in the following format:
# replacer.config.toml
pairs = [
["old text 1", "new text 1"],
["foo", "bar"]
]
case_sensitive = true # Optional, defaults to true
# Ignore Configuration (Optional)
ignore = [".git", "dist", ".env", "ignore_this.txt", "*.ignore"]
Examples
-
Replace text in a directory using a config file:
replacer ./path/to/target
-
Replace text from stdin:
echo "Hello, world!" | replacer
-
Use CLI arguments for replacement pairs:
replacer -p "foo=bar" -p "old=new" ./path/to/target
-
Ignore specific directories:
replacer -i node_modules -i .git ./path/to/target
-
Override ignore settings:
replacer -n important_file.txt ./path/to/target
-
Case-insensitive replacement:
replacer -s -p "HELLO=world" ./path/to/target
Tips
- Flags passed to CLI always override those set in the config file.
- You don't need a config file if you pass pairs as flags.
- Use
--
after flags which take in PATHS (such as -i) to continue the args. - The
.git
directory is ignored by default. - You can use glob patterns in the ignore list, such as
*.log
ortemp*
.
Notes
- When using stdin, the tool will process the input and write the result to stdout.
- If a file can't be read or written, an error message will be displayed, but the program will continue processing other files.
Dependencies
~4.5–6.5MB
~112K SLoC