### Building and Installing fastmod
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Instructions for installing fastmod using cargo or building from source. Includes commands for building, testing, and checking help information.
```bash
# Install directly from crates.io (recommended)
cargo install fastmod
```
```bash
# Or build from source
git clone https://github.com/facebookincubator/fastmod.git
cd fastmod
cargo build --release
./target/release/fastmod --help
```
```bash
# Run the test suite
cargo test
```
```bash
# Check available options
fastmod --help
fastmod --version
```
--------------------------------
### Include Hidden Files with --hidden
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Processes files and directories that start with a dot (hidden files). Useful for configuration files or dotfiles.
```bash
# Apply fix to hidden dotfiles as well
fastmod --accept-all --hidden \
'old_setting' 'new_setting' \
~
```
```bash
# Update .env files
fastmod --accept-all --hidden --extensions env \
'DB_HOST=localhost' 'DB_HOST=127.0.0.1' \
.
```
--------------------------------
### Build fastmod from Source
Source: https://github.com/facebookincubator/fastmod/blob/main/README.md
Follow these steps to clone the fastmod repository, build it using cargo, and access the release binary. This is useful for development or if you need a specific version not available through package managers.
```bash
$ git clone https://github.com/facebookincubator/fastmod.git
$ cd fastmod
$ cargo build --release
$ ./target/release/fastmod --help
```
--------------------------------
### Basic Interactive Find and Replace
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Runs fastmod interactively, showing a colored diff for each match and prompting for user action (accept, reject, edit, quit). Use this for verifying regex changes before applying them broadly.
```bash
# Replace ... with ...
# in all .php and .html files under /home/user/www
fastmod -m -d /home/user/www --extensions php,html \
'(.*?)'
'${2}'
# Interactive prompt shown for each match:
# src/views/header.php:42
# - Error
# + Error
# Accept change (y = yes [default], n = no, e = edit, A = yes to all, q = quit)?
```
--------------------------------
### List Changed Files with --print-changed-files
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Prints the sorted paths of all files that were modified. Recommended with --accept-all for scripting and downstream processing.
```bash
fastmod --accept-all --print-changed-files \
'deprecated_fn\(' 'new_fn(' \
src/
# Example output:
# src/api/handler.rs
# src/core/utils.rs
# src/models/user.rs
```
```bash
# Capture the list for downstream processing (e.g., re-run formatter)
CHANGED=$(fastmod --accept-all --print-changed-files 'foo' 'bar' src/)
echo "$CHANGED" | xargs rustfmt
```
--------------------------------
### Non-Interactive Batch Replacement with --accept-all
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Automatically accepts all changes without prompting, suitable for automated refactors and CI pipelines. This mode utilizes a fully multi-threaded engine.
```bash
# Rename a function across the entire repo, no prompts
fastmod --accept-all 'get_user_by_id\(' 'fetch_user_by_id(' .
# Combine with --print-changed-files to get a list of modified files
fastmod --accept-all --print-changed-files 'TODO' 'FIXME' src/
# Output (sorted):
# src/auth/login.rs
# src/db/query.rs
# src/ui/dashboard.rs
```
--------------------------------
### Perform Regex Replacement with Interactive Review
Source: https://github.com/facebookincubator/fastmod/blob/main/README.md
Use this command to perform a regex replacement across specified file extensions in a directory. It interactively prompts for confirmation of each change, allowing edits or rejections. Ensure correct regex syntax for Rust's regex crate, using `${1}` for capture groups and `$$` for literal '$'. Single quotes around the replacement string are recommended to avoid shell interpretation of '$'.
```bash
fastmod -m -d /home/jrosenstein/www --extensions php,html \
'(.*?)' \
'${2}'
```
--------------------------------
### Specify Target Directory After Regex Arguments
Source: https://github.com/facebookincubator/fastmod/blob/main/README.md
This command demonstrates an alternative syntax where the target directory is provided as a positional argument after the regex and substitution patterns. This is useful for processing a list of files from an external source. Note that fastmod handles directory traversal internally, so piping from `find` might be less efficient.
```bash
fastmod -m --extensions php,html \
'(.*?)' \
'${2}' \
/home/jrosenstein/www
```
--------------------------------
### External Diff Rendering with --diff-tool
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Delegates diff rendering to an external tool instead of fastmod's built-in output. The tool receives old and new file paths as arguments.
```bash
# Use difftastic for structural diffs
fastmod --diff-tool difft \
'OldStruct' 'NewStruct' src/
```
```bash
# Use delta for syntax-highlighted diffs
fastmod --diff-tool delta \
'old_method' 'new_method' .
```
```bash
# Pass options to the diff tool (quote the whole command)
fastmod --diff-tool 'difft --color always' \
'legacy_fn' 'modern_fn' lib/
```
--------------------------------
### Basic Case-Insensitive Replacement
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Performs a case-insensitive replacement of a word across specified files. Use --accept-all to automatically accept all changes.
```bash
fastmod --accept-all --ignore-case \
'colour' 'color' \
./src
```
```bash
fastmod --accept-all -i \
'http://example\.com' 'https://example.com' \
.
```
--------------------------------
### Disable Ignore Rules with -u / --no-ignore
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Processes all files, including those normally ignored by .gitignore, .ignore, or global git exclusion rules. Combine with --hidden to process all files.
```bash
# Also process files listed in .gitignore (e.g., generated code)
fastmod --accept-all --no-ignore \
'v1\.deprecated_api' 'v2.new_api' \
./generated
```
```bash
# Combine with --hidden to reach absolutely every file
fastmod --accept-all --hidden --no-ignore \
'old_token' 'new_token' \
.
```
--------------------------------
### Filter by File Extension with --extensions
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Restricts the search to files with a specified comma-separated list of extensions. This option is mutually exclusive with `--glob` and `--iglob`.
```bash
# Only process .js and .ts files
fastmod --accept-all --extensions js,ts \
'require("lodash")' \
'import _ from "lodash"' \
./frontend
# Only process Python files in the current directory tree
fastmod --accept-all --extensions py \
'print '
'print('
.
```
--------------------------------
### Filter by Glob Pattern with --glob / --iglob
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Filters files using case-sensitive (`--glob`) or case-insensitive (`--iglob`) glob patterns. Multiple patterns can be provided, and this option is mutually exclusive with `--extensions`.
```bash
# Case-sensitive glob: only files named exactly "*.config.js"
fastmod --accept-all --glob '*.config.js' \
'webpack\.dev' 'webpack.prod' .
# Case-insensitive glob: matches "*.txt", "*.TXT", "*.Txt", etc.
fastmod --accept-all --iglob '*.txt' \
'awesome' 'great' ./docs
# Multiple globs
fastmod --accept-all --glob '*.rs' '*.toml' \
'old_crate_name' 'new_crate_name' .
```
--------------------------------
### Positional Path Arguments for Search
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Specifies files and directories to search using positional arguments after the regex and substitution. This method also supports piping input from `find`.
```bash
# Equivalent to using -d, but supports multiple paths and file lists
fastmod -m --extensions php,html \
'(.*?)'
'${2}' \
/home/user/www /home/user/other_project
# Also enables piping from find (note: internal parallel walk is faster)
fastmod 'OldClassName' 'NewClassName' src/ lib/
```
--------------------------------
### Multiline Matching with -m / --multiline
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Enables the `.` character in regex to match newline characters, allowing patterns that span multiple lines. Useful for refactoring multi-line code structures.
```bash
# Collapse a multi-line function call onto one line
fastmod -m --accept-all \
'foo\(\s+bar,\s+baz\s+\)' \
'foo(bar, baz)' \
src/
# Remove blank lines between two specific markers
fastmod -m --accept-all \
'(START_BLOCK)\n\n(END_BLOCK)' \
'${1}\n${2}' \
.
```
--------------------------------
### Capture Groups in Substitutions
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Uses Rust regex crate syntax for capture groups, referenced with ${1}, ${2}, etc. Use $$ for a literal '$'. Single quotes around replacements are recommended.
```bash
# Swap arguments: foo(a, b) -> foo(b, a)
fastmod --accept-all \
'foo\((\w+), (\w+)\)' \
'foo(${2}, ${1})' \
src/
```
```bash
# Wrap a value in a function call: value -> wrap(value)
fastmod --accept-all \
'return (\w+);' \
'return wrap(${1});' \
src/
```
```bash
# Insert a literal dollar sign
fastmod --accept-all \
'price: (\d+)' \
'price: $${1}' \
templates/
# Input: price: 42
# Output: price: $42
```
--------------------------------
### Case-Insensitive Matching with -i / --ignore-case
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Performs a case-insensitive search for both the directory scanner and the replacement regex. This flag affects how patterns are matched against file contents.
```bash
```
--------------------------------
### Literal String Replacement with -F
Source: https://context7.com/facebookincubator/fastmod/llms.txt
Treats the search string as a literal plain string, automatically escaping regex metacharacters. Useful for replacing strings that contain special regex characters.
```bash
# Replace a literal string that contains regex metacharacters
fastmod --accept-all -F \
'foo+bar' 'baz' \
./src
# Input: foo+bar\nfoooobar
# Output: baz\nfoooobar (only the literal "foo+bar" is replaced)
```
```bash
# Replace a dollar sign literally in the replacement
fastmod --accept-all -F \
'something' '$foo.bar' \
./config
# Input: something
# Output: $foo.bar
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.