Skip to content

Instantly share code, notes, and snippets.

@RhysC
Last active December 22, 2015 03:28
Show Gist options
  • Select an option

  • Save RhysC/6410004 to your computer and use it in GitHub Desktop.

Select an option

Save RhysC/6410004 to your computer and use it in GitHub Desktop.
WarmuP equivalent via power shell, using Github. Will take a zip from a given Git-hub location (https://github.com/{OrgOrUserName}/{Project} and pull it down and swap out the old project name for a new project name. You can now push this to a new origin or do what you will.
function Select-UniqueChildrenWithStringPattern {
param($path, $pattern)
Get-ChildItem $path -Recurse -exclude *.exe,*.dll,*.pdb,*.jpg,*.png,*.gif,*.mst,*.msi,*.msm,*.gitignore,*.idx,*.pack,*.suo,*.ico,*.nupkg,*.zip,*.7z |
Select-String -Pattern $pattern |
Where-Object { $_ -ne $null } |
Select-Object Path -Unique
}
function String-ReplaceRecursive {
param($path, $pattern, $replaceValue)
(Select-UniqueChildrenWithStringPattern $path $pattern) |
% {
if(test-path $_.Path){
$content = Get-Content -path $_.Path
$content | % { $_ -replace $pattern , $replaceValue } | Set-Content $_.Path
}
else{
Write-Output ("Path doesnt exist" + $_.Path)
}
}
}
function File-ReplaceTokenRecursive {
param($path, $pattern, $replaceValue)
ls -Path $path -Filter "*$pattern*" -Recurse |
Rename-Item -NewName {$_.Name -replace $pattern, $replaceValue}
}
$ErrorActionPreference = "stop"
$orgName = Read-Host 'What is your git hub base account? eg Organisation name'
$templateProject = Read-Host 'What is the git hub repo you wish to copy?'
$newProject = Read-Host 'What is the new project name?'
$username = Read-Host 'What is your git hub username?'
curl -u $username -L -O https://github.com/$orgName/$templateProject/archive/master.zip
Expand-Archive -Path '.\master.zip' -OutputPath '.\' -Force -ShowProgress
robocopy "$templateProject-master" "." /E /MOVE
String-ReplaceRecursive . $templateProject $newProject
File-ReplaceTokenRecursive . $templateProject $newProject
rm .\master.zip -Force
@RhysC

RhysC commented Sep 2, 2013

Copy link
Copy Markdown
Author

Input stream can get in the mix so we test path before string replacement

@RhysC

RhysC commented Sep 2, 2013

Copy link
Copy Markdown
Author

Excluding binaries

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