So I've been sharing a number of PowerShell tools I've created for working with Git, including a few for getting tips from the Git Tips project on GitHub. My initial work was based on the fact that I had a local clone of that repository and wanted to search the local tips.json file. But I realized some of you may not want to clone the repository or be able to keep it up to date. Since the json file is available online and PowerShell has tools for grabbing Internet content, I decided to provide a version that combines the functionality of my earlier commands with the ease of searching online.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
PowerShell has several cmdlets you can use for getting web content. I'm using Invoke-RestMethod primarily because it will automatically convert the downloaded json data into objects.
$params = @{ Uri = "https://raw.githubusercontent.com/git-tips/tips/master/tips.json" ErrorAction = "Stop" } Write-Verbose "Retrieving tips from $($params.uri)" $tips = Invoke-RestMethod @params
Once I've downloaded the tips I can do whatever I want. I can select a single, random tip, display them all or search the tip title. My new command offers all of these options.
Once I dot source the command into my PowerShell session (or load it in your profile) I can get all tips from the online json file which is the default behavior.
I can also search, including using regular expressions if I wanted.
Finally, I can use this function as my tip of the day by getting a random tip.
I even added a parameter to make it "pretty" using Write-Host.
Again, none of this requires that you have a clone of the GitHub repository or even have git installed. If have encounter any issues with the function, please post them in a comment on the Gist page.
Enjoy and hoping you have an unfor-Git-able week!