Created
March 14, 2025 06:48
-
-
Save bokwoon95/ca8304ea31e68bc1796d01debea42d9e to your computer and use it in GitHub Desktop.
grepf.ps1 / rgrepf.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env pwsh | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true, Position=0)] | |
[string]$str, | |
[Parameter(ValueFromRemainingArguments=$true)] | |
[string[]]$args | |
) | |
rg $str @args |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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