Skip to content

Instantly share code, notes, and snippets.

@bokwoon95
Created March 14, 2025 06:48
Show Gist options
  • Save bokwoon95/ca8304ea31e68bc1796d01debea42d9e to your computer and use it in GitHub Desktop.
Save bokwoon95/ca8304ea31e68bc1796d01debea42d9e to your computer and use it in GitHub Desktop.
grepf.ps1 / rgrepf.ps1
#!/usr/bin/env pwsh
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=0)]
[string]$str,
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$args
)
rg $str @args
#!/usr/bin/env pwsh
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=0)]
[string]$old,
[Parameter(Mandatory=$true, Position=1)]
[string]$new,
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$args
)
if ($args -contains '-F') {
rg $old -l @args | ForEach-Object { [System.IO.File]::WriteAllText((Join-Path $PWD $_), [System.IO.File]::ReadAllText((Join-Path $PWD $_)).Replace($old, $new)) }
} else {
rg $old -l @args | ForEach-Object { [System.IO.File]::WriteAllText((Join-Path $PWD $_), ([System.IO.File]::ReadAllText((Join-Path $PWD $_)) -replace $old, $new)) }
}
rg $new @args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment