Skip to content

Command Explorer doesn't sort like Show-Command #1993

Open
@corbob

Description

@corbob

The original intent behind Command Explorer was to mimic Show-Command. I noticed today that Show-Command sorts with the hyphens being of higher sort value than other letters. While the Sort-Object that we use in the Command Explorer seems to strip out the hyphens and sorts based on the result. So you'll see some Convert-Toxxx and then ConvertTo-yyy followed by Convert-Tozzz.

System Details

This happens with Windows PowerShell 5.1 on Windows 10 1709 and insiders build 18898 as well as PowerShell Core 6.2. As such, I'm going to forego the vscode version and PSES.

Issue Description

Example of 4 made up functions:

PS> function ConvertTo-Lkj {}
PS> function Convert-ToLkj {}
PS> function Convert-Lkj {}
PS> function ConvertLkj {}

When running Show-Command and then sorting for lkj:
Show-Command sorting for made up cmdlets

When running the equivalent Get-Command code Get-Command *lkj | select name | Sort name | ogv:
Get-Command equivalent of Show-Command sorting for made up cmdlets

I have also tested this in pwsh with the same behavior:

PS> function ConvertTo-Lkj {}
PS> function Convert-ToLkj {}
PS> function Convert-Lkj {}
PS> function ConvertLkj {}
PS> get-command *lkj | select name | sort name

Name
----
ConvertLkj
Convert-Lkj
ConvertTo-Lkj
Convert-ToLkj

Expected Behaviour

Output commands in the order:

Convert-Lkj
Convert-ToLkj
ConvertLkj
ConvertTo-Lkj

Actual Behaviour

Output commands in order:

ConvertLkj
Convert-Lkj
ConvertTo-Lkj
Convert-ToLkj

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions