PowerShell: Tab completion of Windows commands is not aligned with cross-platform "best practice"
Summary of the new feature / enhancement
According to an article on powershell.org:
On Windows, executable files have the .exe extension. On Linux/MacOS, an executable has file system permissions that mark a file as executable. If you’re searching for or running a command that could exist on all operating systems, omit the extension from the name. On Windows, PowerShell will implicitly add the .exe extension for you (it actually uses the extensions in the PATHEXT environment variable to look for commands).
The issue is that PS7 tab-completion does not follow this guideline for Windows executables. For example, typing dot[Tab]
results in dotnet.exe
, not dotnet
.
Proposed technical implementation details (optional)
Tab-completion for executables should follow the format basename
, not basename.ext
.
Either that or the extension appears, but in dark-grey.
An alternative would be to tab-complete to the basename, and a second tab would add the extension.
So robo[Tab]
gives Robocopy
, and robo[Tab][Tab]
gives Robocopy.exe
.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (3 by maintainers)
Agreed, @jhoneill, but my point was that even if you carefully manage the scope of your strict-mode settings to avoid affecting other code - which you should always do - even your own code is at risk of breaking if you ship something with
Set-StrictMode -Latest
in effect, given that if a future PowerShell version introduces a new strict-mode version with even more stringent checks, your code may then fail those checks.The WG reviewed this issue. The tab completion is just resolving the filename. On the Windows platform, that includes the extension. Changing that behavior can be risky. If you are scripting for cross-platform scenarios it is your responsibility to handle using the proper name of the executable on the target platforms. Tab expansion was never meant to be cross-platform aware.
First off a quick apology if my tone was bit snappy - was trying to answer with people screaming around me
This makes more sense, because there is a long history of the current behaviour and changing it will annoy at least as many people as it pleases. This way everyone can be happy.
To me it’s a complete non issue at the command line, you’re told the file name explicitly, it runs, end of story. When tab expansion is completing something for a script, it would mean than a script written on Windows to run
git.exe
won’t rungit
on linux. For every person who sees this as a problem, another will want the full name. So the preference setting is a chance to please both sides.If you have a windows EXE with the same name as a PowerShell alias like SORT. The .EXE is needed.
You may also have multiple files with the same name in different places. I have install.exe, install.bat, install.cmd and install.ps1 files
It’s not really a “cross platform best practice”