Question:
Suppose I have the following folder: C:\[test]\x
, then, when inside of the [test]
folder, I can’t use PowerShell’s tab completion at all.
I guess the reason for that is that the folder name would need to be escaped to ´[test´]
(with the ticks inverted, which causes Markdown problems here), as it the completion does when tabbing from inside C:\
.
I don’t really care about the missing tab completion when inside of C:\
and typing [t...
, but I would like to use the tab completion within that folder. Is there any way to fix that behaviour?
Answer:
PowerShell and many its features in general do not work well with paths with special symbols, [
and ]
symbols in the first place. We cannot fix the PowerShell core but we can fix/replace some features. TabExpansion is one of them. It’s just a global function that can be replaced with an improved implementation.
Several custom TabExpansion implementations can be found here and there. I am using my own. It is host agnostic (at least its works well with Console, ISE, and my own host), it is reasonably simple and yet it provides a lot of improvements. Your particular problem is resolved, too.
The code of TabExpansion (dot-source it in or simply call it from your PowerShell profile):
http://code.google.com/p/farnet/source/browse/trunk/PowerShellFar/TabExpansion.ps1
Some of its features are covered by this test:
http://code.google.com/p/farnet/source/browse/trunk/PowerShellFar/Bench/Test/Test-TabExpansion-.ps1
(The test works only in the special environment, do not run it, just take a look at comments in the code to see what TabExpansion can do).