Skip to content

Instantly share code, notes, and snippets.

@brunomartinspro
Created August 31, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomartinspro/ffae4e403d61934a1c961d51fb9b2dc3 to your computer and use it in GitHub Desktop.
Save brunomartinspro/ffae4e403d61934a1c961d51fb9b2dc3 to your computer and use it in GitHub Desktop.
Groovy Wonderland - Enables locating parallel files in parallel universes!
param ([switch]$delete)
$currentLocation = Get-Location
$counter = 1
if(!$delete) {
Get-ChildItem $currentLocation -Filter "*.groovy" -recurse | Foreach-Object {
Write-Output ("----------------- File Start: " + $_.FullName + "----------------------")
try {
$regex = '(def call\(body\) \{)'
(Get-Content $_.FullName) -replace $regex, "def call(body) { $([Environment]::NewLine) println('CodeName: Wonderland ($counter)')" | Set-Content $_.FullName
$counter += 1
Write-Output (Get-Content $_.FullName)
}
catch {
Write-Output ("Error: $_")
}
Write-Output ("----------------- File End: " + $_.FullName + "----------------------")
}
Write-Output ("Welcome to the Wonderland!")
}
else {
Get-ChildItem $currentLocation -Filter "*.groovy" -recurse | Foreach-Object {
Write-Output ("----------------- File Start: " + $_.FullName + "----------------------")
try {
$regex = "(println\(\'CodeName\: Wonderland \(.*\)\'\))"
(Get-Content $_.FullName) -replace $regex, "" | Set-Content $_.FullName
Write-Output (Get-Content $_.FullName)
}
catch {
Write-Output ("Error: $_")
}
Write-Output ("----------------- File End: " + $_.FullName + "----------------------")
}
Write-Output ("Hope you liked the Wonderland!")
}
@brunomartinspro
Copy link
Author

Usage

Run the script in your current location.

Create

GroovyWonderland.ps1 

Delete

GroovyWonderland.ps1 -delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment