Bringing Hump Completion to PowerShell


It can be fun when ideas from different areas combine!

I’ve spent quite a lot of time recently working with Azure Resource Manager templates, and the associated PowerShell cmdlets. There are a lot of these cmdlets and the team has done a great job of giving them logical and descriptive names. The result is that the names are quite long, for example:

Get-AzureRmOperationalInsightsWorkspaceManagementGroups

To get anywhere close to the command that you want you need to type quite a lot of the cmdlet name before hitting tab. For example, if you typed “Get-AzureRmOp” then tab completion would cycle through:

Get-AzureRmOperationalInsightsLinkTargets
Get-AzureRmOperationalInsightsStorageInsight
Get-AzureRmOperationalInsightsWorkspace
Get-AzureRmOperationalInsightsWorkspaceManagementGroups
Get-AzureRmOperationalInsightsWorkspaceSharedKeys
Get-AzureRmOperationalInsightsWorkspaceUsage

So you’d only need four tabs, but you had to already have typed “Get-AzureRmOp” Smile

This problem feels familiar. When you’re writing code and buy in to descriptive names you end up with the same challenges. A popular way to deal with this is to use “Hump Completion”. So if I have the following C# classes then I’m faced with the same problem when I come to refer to the class.

class SomeClassWithAReallyLongName     { }
class SomeClassWithAnEspeciallyLongNameJustToMakeAPoint { }

Visual Studio (and other products such as ReSharper) give us a nice way to handle this – we can just use the capitals. The screenshot below shows the IntelliSense when entering “new SCW

image

At this point I wanted the same sort of behaviour in PowerShell! Enter posh-HumpCompletion.

Going back to the PowerShell example above, posh-HumpCompletion enables you to type “Get-ARO” and then hit tab to get the same set of tab expansions to cycle through.

After working with it for a while I’ve found that there are quite a few cmdlets that I use frequently enough that my fingers type the hump form automatically. E.g. “Get-ARRG<tab>” gets me “Get-AzureRmResourceGroup

posh-HumpCompletion

Installation

At the time of writing this post, you can choose to install via Chocolatey or the PowerShell Gallery. Full details here: https://github.com/stuartleeks/posh-HumpCompletion/blob/master/README.md#installation

For the PowerShell Gallery approach:

Install-Module -Name posh-HumpCompletion

Note

For performance, posh-HumpCompletion caches the loaded commands. If you load new modules or otherwise change the set of commands (Azure PowerShell & Switch-AzureMode, I’m looking at you!) then run Clear-HumpCompletionCommandCache to reset. [Bonus tip: use "Clear-HCCC<tab>" :-)]

Comments (0)

Skip to main content