question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect sort order when using tab completion and listing items

See original GitHub issue

Prerequisites

Steps to reproduce

I am inside a directory that looks as follows. Notice how it’s listing out files in the incorrect order! This applies to tab completion as well and the “broken” items will be completed before the correct items. There must be a sort-order bug someplace…

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           5/29/2023  5:26 AM           6060 check_cmake_consistency_config.py    <-- broken; wrong order
-a---           5/29/2023  5:26 AM          14928 check_cmake_consistency.py
-a---           5/29/2023  5:26 AM           5119 check_deprecated.py
-a---           5/29/2023  5:26 AM           6025 check_descriptions.py
-a---           5/29/2023  5:26 AM           2147 check_header_duplicate.py
-a---           5/29/2023  5:26 AM          15793 check_licenses.py
-a---           5/29/2023  5:26 AM           3792 check_mypy_config.py    <-- broken; wrong order
-a---           5/29/2023  5:26 AM           2908 check_mypy.py
-a---           5/29/2023  5:26 AM          13648 check_spelling_c_config.py    <-- broken; wrong order
-a---           5/29/2023  5:26 AM          23475 check_spelling.py
-a---           5/29/2023  5:26 AM           2524 check_unused_defines.py

Expected behavior

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           5/29/2023  5:26 AM          14928 check_cmake_consistency.py
-a---           5/29/2023  5:26 AM           6060 check_cmake_consistency_config.py
-a---           5/29/2023  5:26 AM           5119 check_deprecated.py
-a---           5/29/2023  5:26 AM           6025 check_descriptions.py
-a---           5/29/2023  5:26 AM           2147 check_header_duplicate.py
-a---           5/29/2023  5:26 AM          15793 check_licenses.py
-a---           5/29/2023  5:26 AM           2908 check_mypy.py
-a---           5/29/2023  5:26 AM           3792 check_mypy_config.py
-a---           5/29/2023  5:26 AM          23475 check_spelling.py
-a---           5/29/2023  5:26 AM          13648 check_spelling_c_config.py
-a---           5/29/2023  5:26 AM           2524 check_unused_defines.py

Actual behavior

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           5/29/2023  5:26 AM           6060 check_cmake_consistency_config.py    <-- broken; wrong order
-a---           5/29/2023  5:26 AM          14928 check_cmake_consistency.py
-a---           5/29/2023  5:26 AM           5119 check_deprecated.py
-a---           5/29/2023  5:26 AM           6025 check_descriptions.py
-a---           5/29/2023  5:26 AM           2147 check_header_duplicate.py
-a---           5/29/2023  5:26 AM          15793 check_licenses.py
-a---           5/29/2023  5:26 AM           3792 check_mypy_config.py    <-- broken; wrong order
-a---           5/29/2023  5:26 AM           2908 check_mypy.py
-a---           5/29/2023  5:26 AM          13648 check_spelling_c_config.py    <-- broken; wrong order
-a---           5/29/2023  5:26 AM          23475 check_spelling.py
-a---           5/29/2023  5:26 AM           2524 check_unused_defines.py

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
mklement0commented, Jun 3, 2023

.NET’s sorting behavior on Windows changed with .NET 5’s move to cross-platform, ICU-based internationalization, as described in .NET globalization and ICU. PowerShell v7.1+ is based on .NET 5+

Therefore, the sort order of _ vs. . is now different relative to Windows PowerShell (based on .NET Framework, which uses Windows-specific NLS sorting rules), and explains your experience:

# WinPS:    -> '.', '_' 
# PS v7.1+: -> '_', '.' 
'.', '_' | Sort-Object

In PS Core, Get-ChildItem performs its own sorting on all platforms, using case-insensitive current-culture sorting (as Sort-Object does by default): https://github.com/PowerShell/PowerShell/blob/1f02772fd97fea7395fbb7b68e2befd5790db392/src/System.Management.Automation/namespaces/FileSystemProvider.cs#L1632-L1633.

1reaction
MartinGC94commented, Jun 3, 2023

.NET’s sorting behavior on Windows changed with .NET 5’s move to cross-platform, ICU-based internationalization, as described in .NET globalization and ICU.

Neat. From that article it seems you can see an environment variable to revert this change in behavior: image

Of course you should be careful about setting this because it affects more than just sorting but it’s good to know that users have some control over this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect sort order when using tab completion and listing ...
Incorrect sort order when using tab completion and listing items · Summary · Jobs. Rebase · Run details. Usage · Workflow file.
Read more >
bash - How to order files by date in tab completion list
I currently use special script to list N most recent files in a given directory (and copy the filename manually into command line),...
Read more >
Sort tab-completion suggestions (files first, then directories ...
When showing file names, directories are highlighted (see 'highlight' option). Names where 'suffixes' matches are moved to the end. The ' ...
Read more >
jQuery Autocomplete order of results
the server takes care of returning the results in the order I would want them to appear but autocomplete shows them in a...
Read more >
bash - Tab completion doesn't work for commands
2) With shopt -s nullglob enabled, trying to tab complete a directory or a file will instead lead to everything being listed, with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found