prevent PowerShell autocomplete from adding dot prefix
See original GitHub issueSummary of the new feature / enhancement
Please provide an option or configuration to prevent PowerShell from prefixing every relative file path (even program arguments!) with a .\
without my asking it to
I understand why PowerShell requires that I prefix a command foo.exe
with .\foo.exe
when I run it. So if I am typing a command fo
and hit Tab
, autocomplete changes what I typed to .\foo.exe
. I can live with that, even though I find it annoying and patronizing.
The problem is when foo.exe
takes command-line arguments, and one of them is the bar.dat
file. If I’m typing .\foo.exe ba
and hit Tab
, I want to get .\foo.exe bar.dat
. I do not want to get .\foo.exe .\bar.dat
. Not only is this irritating as heck (not to mention ugly), it actually breaks some of my commands, which don’t allow any directory (even the current directory) to be specified in the argument.
How do I turn off this PowerShell quirk of adding a .\
to every single autocomplete for a relative path? As far as I’m concerned, I’d like it to be turned off everywhere—I can remember to type .\foo.exe
instead of foo.exe
for the initial command. As I mentioned earlier, I can partially understand that PowerShell wants to add the .\
to the initial command, because it’s required to run a program in the current directory. But I’m dumbfounded as to why PowerShell is so unintelligent that it blindly adds the .\
prefix to all relative paths, even where it’s not required, not needed, and certainly not desired.
I opened prevent PowerShell autocomplete from adding dot prefix on Super User, but no one had any solutions.
Proposed technical implementation details (optional)
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:22 (11 by maintainers)
Nicely done, @MartinGC94. I suggest tweaking the code a bit (I’ve done it below) so as to treat
./
the same as\.
, and to prevent the removal of these prefixes if the token being tab-completed represents a command.That’s a reasonable conclusion, and I’m not saying that PowerShell should remove its more helpful behavior in relation to the initial command. I was just saying it’s not necessarily “wrong” to do it the other way. Both Bash and PowerShell take a “I’ll blindly do path completion the same way for all relative paths.” I guess my point is that if it has to be all or nothing, I much prefer the Bash approach, which results in fewer things I didn’t ask for.
But we shouldn’t be stuck with two blind approaches. I’m sure PowerShell can be made smart enough to figure out if the path relates to the initial command or an argument. (And I think it’s worth noting that the logic to avoid this behavior surely would be many times shorter than the workaround.)
I don’t disagree. The point I was making is that the purported purpose of adding
.\
to the command is because it is necessary for functionality, and I was noting that PowerShell is adding it even when it’s not necessary for functionality. If someone still wants PowerShell to add the prefix because it looks prettier to them, that’s a valid opinion, but that’s a different argument than functional utility.I also want to say that your four points at the start of your comment above are an excellent summary, and I agree with them all.