Skip to content

Environment Variables

Mikhail Deynekin edited this page Apr 11, 2026 · 1 revision

⚙️ Environment Variables

Complete reference for all environment variables supported by sr.

Configuration Precedence

  1. Command-line arguments (highest priority)
  2. Environment variables (SR_*)
  3. Script defaults (lowest priority)

Core Behavior

Variable Default Description
SR_DEBUG false Enable debug output
SR_DRY_RUN false Test mode without modifications
SR_NO_BACKUP false Disable backup creation
SR_FORCE_BACKUP false Force backup even when no changes
SR_MAX_DEPTH 100 Maximum directory recursion depth
SR_VERBOSE false Enable verbose output

Safety Limits

Variable Default Description
SR_MAX_FILE_SIZE_MB 50 Skip files larger than this (MB)
SR_BINARY_CHECK_SIZE 2048 Bytes to check for binary detection
SR_MAX_BACKUPS 20 Maximum number of backup sessions to keep

Search Behavior (v6.1.0)

Variable Default Description
SR_IGNORE_CASE false Case-insensitive matching
SR_EXTENDED_REGEX false Use extended regular expressions
SR_WORD_BOUNDARY false Match whole words only
SR_GLOBAL_REPLACE true Replace all occurrences per line

Tool Configuration (v6.1.0)

Variable Default Description
SR_FIND_FLAGS "" Default flags for find command
SR_SED_FLAGS "" Default flags for sed command
SR_GREP_FLAGS "-F" Default flags for grep command

Usage Examples

Set Defaults for a Session

# Enable verbose and limit depth
export SR_VERBOSE=true
export SR_MAX_DEPTH=5
export SR_MAX_FILE_SIZE_MB=10

# Now all sr commands use these defaults
sr "*.conf" "old-value" "new-value"

Tool-Specific Configuration

# Configure grep to skip comment lines
export SR_GREP_FLAGS="-v '^#'"

# Enable extended regex by default
export SR_EXTENDED_REGEX=true

# Use custom find flags
export SR_FIND_FLAGS="-type f -mtime -7"

Safety Configuration

# Production safety settings
export SR_MAX_FILE_SIZE_MB=10
export SR_NO_BACKUP=false
export SR_FORCE_BACKUP=true
export SR_MAX_BACKUPS=30
export SR_MAX_DEPTH=10

Team/Project Wrapper

#!/bin/bash
# File: /usr/local/bin/sr-project
# Project-specific sr configuration

export SR_MAX_DEPTH=3
export SR_NO_BACKUP=false
export SR_VERBOSE=true
export SR_EXCLUDE_DIRS="node_modules,dist,.git"

/usr/local/bin/sr "$@"

Exclude Configuration

Variable Default Description
SR_EXCLUDE_DIRS .git,node_modules Comma-separated directories to exclude
SR_EXCLUDE_PATTERNS "" File patterns to exclude
SR_ALLOW_HIDDEN false Process hidden files/directories
SR_ALLOW_BINARY false Allow binary file processing
SR_BINARY_DETECTION_METHOD multi_layer Binary detection: multi_layer, file_only, grep_only

Related Topics

Clone this wiki locally