Skip to content

Instantly share code, notes, and snippets.

@neogeogre
Created August 18, 2022 08:26
Show Gist options
  • Save neogeogre/75ce026ff7754e0157f1faeae232c403 to your computer and use it in GitHub Desktop.
Save neogeogre/75ce026ff7754e0157f1faeae232c403 to your computer and use it in GitHub Desktop.
Edit plenty of git repos at once
import java.io.File
import java.lang.ProcessBuilder.Redirect.INHERIT
import java.nio.file.Files
import java.util.concurrent.TimeUnit.MINUTES
import kotlin.io.path.Path
const val ROOT = "/home/geoffrey/Desktop/gitlab"
fun main() = Files
.walk(Path(ROOT), 1)
.toList()
.map { it.toFile() }
.filter { it.name != File(ROOT).name }
.forEach { "git remote set-url origin codecommit://${it.name}".runCommand(it) }
fun String.runCommand(executionDirectory: File) =
ProcessBuilder(*split(" ").toTypedArray())
.directory(executionDirectory)
.redirectOutput(INHERIT)
.redirectError(INHERIT)
.start()
.waitFor(60, MINUTES)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment