PowerShell / PowerShell/vscode-powershell

Command Explorer doesn't sort like Show-Command

Open
#1,993 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Command Explorer Issue-Enhancement
Dominant language
TypeScript
Stars
1.9k
Forks
547
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Command Explorer sorting path and locating the Sort-Object behavior described in the issue. Reproduce the four sample command names, compare the result with Show-Command, and consider the work done when Command Explorer orders them as shown under Expected Behaviour.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.