Incorrect sort order when using tab completion and listing items
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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:
- Created 4 months ago
- Comments:12 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
.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:In PS Core,
Get-ChildItem
performs its own sorting on all platforms, using case-insensitive current-culture sorting (asSort-Object
does by default): https://github.com/PowerShell/PowerShell/blob/1f02772fd97fea7395fbb7b68e2befd5790db392/src/System.Management.Automation/namespaces/FileSystemProvider.cs#L1632-L1633.Neat. From that article it seems you can see an environment variable to revert this change in behavior:
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.