Created
February 10, 2018 20:29
-
-
Save samiru/0f4d11ec982b23e5df4a773bc5063f79 to your computer and use it in GitHub Desktop.
Pulls Gists from Github.
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
| <# | |
| Pulls Gists from Github. | |
| Inspiration taken from http://amatashkin.com/2013/09/18/backup-all-public-gists-with-powershell/ | |
| #> | |
| param ( | |
| [string]$githubname = "samiru" | |
| ) | |
| if ($githubname -eq "") { | |
| Write-Host("Please provide Github user name as parameter!") | |
| Exit | |
| } | |
| $initpath = Get-Location | |
| # Create directory for gists if it does not exist | |
| if (!(Test-Path -path "gists")) { | |
| New-Item -Path "gists" -ItemType Directory | |
| } | |
| $gistspath = Join-Path $initpath -ChildPath "gists" | |
| Set-Location $gistspath | |
| # Get gist repository urls | |
| $gistjson = ConvertFrom-Json (Invoke-WebRequest https://api.github.com/users/$githubname/gists).content | |
| $gisturls = $gistjson.git_pull_url | |
| # Pull or clone the gist | |
| foreach ($url in $gisturls) { | |
| $gistname = [regex]::Match($url, ".*\/(.*)\.git").captures.groups[1].value | |
| Write-Host $gistname | |
| if (!(Test-Path -path $gistname)) { | |
| Invoke-Expression "git clone $url" | |
| } | |
| else { | |
| Set-Location $gistname | |
| Invoke-Expression "git pull $url" | |
| Set-Location $gistspath | |
| } | |
| } | |
| Set-Location $initpath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment