Skip to content

Instantly share code, notes, and snippets.

@jdhitsolutions
Last active April 9, 2018 15:27
Show Gist options
  • Save jdhitsolutions/c3da8a276b3d1fe7a900ac659a79a5e8 to your computer and use it in GitHub Desktop.
Save jdhitsolutions/c3da8a276b3d1fe7a900ac659a79a5e8 to your computer and use it in GitHub Desktop.
This function will search the Tips.json file from the Git-Tips project on GitHub. You will need to clone or download the git-tips project locally from https://github.com/git-tips/tips.
#requires -version 4.0
Function Find-GitTip {
<#
.Synopsis
Search Git tips
.Description
This function will search the Tips.json file from the Git-Tips project on GitHub. You will need to clone or download the git-tips project locally from https://github.com/git-tips/tips.
.Parameter Text
The search term which can be a regular expression pattern.
.Parameter Path
The path to the tips.json file from the GitHub project.
.Example
find-gittip status
title tip
----- ---
Status of ignored files. git status --ignored
Find all tips with 'status' in the tip title.
.Example
find-gittip \bignore\b | format-list
title : Ignore one file on commit (e.g. Changelog).
tip : git update-index --assume-unchanged Changelog; git commit -a; git update-index
--no-assume-unchanged Changelog
title : Ignore file mode changes on commits
tip : git config core.fileMode false
Find all tips that contain the word 'ignore' and display as a formatted list.
.Notes
version: 1.0
Learn more about PowerShell:
http://jdhitsolutions.com/blog/essential-powershell-resources/
.Link
ConvertFrom-Json
.Link
https://github.com/git-tips/tips
#>
[cmdletbinding()]
Param(
[Parameter(
Position = 0,
Mandatory,
HelpMessage = "enter a search word or regex pattern."
)]
[ValidateNotNullorEmpty()]
[string]$Text,
[ValidateScript({
if (Test-Path $_) {
$True
}
else {
Throw "Cannot validate path $_"
}
})]
[string]$Path = 'c:\scripts\tips\tips.json'
)
Write-Verbose "Starting: $($MyInvocation.Mycommand)"
Write-Verbose "Searching for $text from $path"
#convert each to a pscustomobject
Get-Content -Path $path | ConvertFrom-Json |
foreach {$_ -as [pscustomobject]} |
where {$_.title -match $text}
Write-Verbose "Ending: $($MyInvocation.Mycommand)"
}
#define an alias
Set-Alias -Name greptip -Value Find-GitTip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment