How do I change the default Powershell CLI behavior to ignore file extensions for filetypes that live on my $Env:Path
environment variable?
If I just type python
, it works correctly and drops me into the Python interpreter as I expect since the extension is part of the environment variable.
The problem is that when I type pyth
and tab-complete in PowerShell, it always appends the .exe
. I just want it to finish the first part of the command without the extension.
Is this possible? Maybe a script?
Best Answer
You can override the standard tab completion function with your own. In the newest version of PowerShell, that function is
TabExpansion2
. This modification of it appears to do what you want:I added the lines after the one that starts with
$field
; it goes through the default tab completion options and lops the extension off ones that appear to be from yourPATH
. I got the original source with this command:If you put the new function in a
.ps1
file and dot-execute that script (e.g.. .\tabnoext.ps1
), it will become the tab completion handler for the current session. To load it every time you open a PowerShell window, just paste all that code into a PowerShell profile script.If you're on an old version of PowerShell, you need to override the
TabExpansion
function, which just returns an array of strings.