Created
June 24, 2016 13:10
-
-
Save jdhitsolutions/60856313d5b4b249af35275c0bbe1ee9 to your computer and use it in GitHub Desktop.
A PowerShell script to display a random Git tip of the day.
This file contains 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
#requires -version 4.0 | |
<# | |
Display a random Git tip of the day to the console. | |
This script does not write anything to the pipeline. | |
You will need to clone or download the git-tips project locally | |
from https://github.com/git-tips | |
This script is described at http://bit.ly/1OgpK7O | |
#> | |
[cmdletbinding()] | |
Param( | |
[Parameter(Position=0, HelpMessage = "The path to a json file with git tips")] | |
[ValidateScript({ | |
if (Test-Path $_) { | |
$True | |
} | |
else { | |
Throw "Cannot validate path $_" | |
} | |
})] | |
[string]$Path = 'c:\scripts\tips\tips.json' | |
) | |
Begin { | |
Write-Verbose "[BEGIN ] Starting: $($MyInvocation.Mycommand)" | |
$alternatetitle = @" | |
...................... | |
. Git Tip of The Day . | |
...................... | |
"@ | |
$title = @" | |
---------------------- | |
Git Tip of The Day | |
---------------------- | |
"@ | |
} #begin | |
Process { | |
Write-Host $title -ForegroundColor Yellow -BackgroundColor DarkGray | |
#Get all of the tips | |
Write-Verbose "[PROCESS] Selecting a random tip from $path" | |
Get-Content -path $path | ConvertFrom-Json | | |
Get-Random -Count 1 | | |
foreach { | |
Write-Host $_.Title -ForegroundColor Green | |
Write-Host $_.tip -ForegroundColor cyan | |
#write a blank line | |
Write-Host " " | |
} | |
} #process | |
End { | |
Write-Verbose "[END ] Ending: $($MyInvocation.Mycommand)" | |
} #end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment