Powershell functions for versioning a git repo with tags and more!
This module is essentially my personal PowerShell toolbelt: a collection of functions that I myself use on a regular basis at work and on the side. It originally started with just the four commands to create semantically versioned tags in git repositories, but has expanded into the smorgasbord of semi-related functionality you see here today.
...at a glance. For more details, check out the wiki.
Easily add semantically versioned tags to your git commits with the following functions:
Add-MajorVersionTag
: Create a new tag with the major version incremented.Add-MinorVersionTag
: Create a new tag with the minor version incremented.Add-PatchVersionTag
: Create a new tag with the patch version incremented.New-VersionTag
: Create a new tag with an arbitrary version number.
The Major, Minor, and Patch functions will find the most recent semantically versioned tag and use it as the basis for the incrementation operation, according to semantic versioning rules.
Delete all local branches in a git repo except for master. Useful for those moments when you realize you have an enormous number of obsolete branches that are ready for the big -D
.
Remove-LocalBranches
By default, this will only remove merged branches. Use -Force
to delete both merged and unmerged branches.
Why fish around for Visual Studio solution files using Windows Explorer when you can find and launch them from your terminal window with just three little letters? Run sln
(an alias for Open-Solution
) to recursively search your current working directory for a solution file and launch it, if one is found.
When you use the New-ModuleManifest
cmdlet to create a module manifest, it generates a lot of comments that you may not want to keep. Run Remove-ModuleManifestComments
to strip away that noise and make your manifest easy to read.
In order to create a well-formed PowerShell module manifest, it's "recommended" that you explicitly list out all functions, cmdlets, variables, and aliases that should be exported. I say "recommended" with quotes because using wildcards for these lists - while technically allowable - will break module autoloading in PowerShell 6. (This doesn't appear to be an issue with PowerShell 5.) So if module autoloading is important to you and you want to target PowerShell 6, you're pretty much required to explicitly list these items out. Regardless of all that, the reason we're encouraged/required to list these out is for performance. Loading all cmdlets, functions, aliases, and variables from a large module can be a surprisingly slow process.
Okay, I get it. Autoloading only essential functionality from a module makes things faster. The problem is that manually listing out all functions, cmdlets, variables, and aliases from an even moderately complex module is a pain in the ass! What if a name changes? What if functionality is removed or added? Am I supposed to remember to manually update my manifest? Fat chance.
This called for some good, old fashioned automation and a few new cmdlets to export function, cmdlet, variable, and alias names from binary modules and scripts. That way I can reconstruct my module manifest dynamically at build time, like this (truncated below):
$moduleInfo = Get-Module WhatsNew
$cmdletNames = Export-BinaryCmdletNames -ModuleInfo $moduleInfo
$cmdletAliases = Export-BinaryCmdletAliases -ModuleInfo $moduleInfo
$scriptFiles = Get-ChildItem -Path "$PSScriptRoot\src\script-modules" -File
$scriptAliases = $scriptFiles |
Select-Object -ExpandProperty FullName |
Export-PSScriptAliases
$scriptFunctions = $scriptFiles |
Select-Object -ExpandProperty FullName |
Export-PSScriptFunctionNames
$newManifestArgs = @{
ModuleVersion = $Version
AliasesToExport = $cmdletAliases + $scriptAliases
NestedModules = $modules
CmdletsToExport = $cmdletNames
FunctionsToExport = $scriptFunctions
}
New-ModuleManifest @newManifestArgs
...for your GitHub wiki home page, just like this with the New-MarkdownTableOfContents cmdlet.
Pro Tip: Install ClipboardText to pipe your ToC right to your clipboard.
Microsoft has a bunch of pretty wallpaper images that are free for the taking. The only problem is that you can only download one image at a time. Laaaame. Well, not any more. Now all you have to do is run Get-MicrosoftDesktopWallpaper
, specify one or more categories of images, and in a few minutes you're done.
Get-MicrosoftDesktopWallpaper
-OutDirectory 'C:\Users\Me\Images\Wallpaper'
-Categories Animals,NaturalWonders,Panoramic,PlacesAndLandscapes
If you happen to use platyPS to create markdown documentation for PowerShell modules (as I do), you may have noticed that the metadata platyPS emits as yaml front matter doesn't render all that nicely on GitHub. Use Switch-YamlFrontMatterToCodeFence to make it pretty on GitHub and Switch-CodeFenceToYamlFrontMatter to switch it back as needed.
Get it from the PowerShell Gallery:
Install-Module -Name WhatsNew