Skip to content

Instantly share code, notes, and snippets.

@jdhitsolutions
Created June 24, 2016 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jdhitsolutions/60856313d5b4b249af35275c0bbe1ee9 to your computer and use it in GitHub Desktop.
Save jdhitsolutions/60856313d5b4b249af35275c0bbe1ee9 to your computer and use it in GitHub Desktop.
A PowerShell script to display a random Git tip of the day.
#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