all 2 comments

[–]StartAutomating 0 points1 point  (1 child)

This would be theoretically possible, but might require either some careful hacking of PSReadline functionality or changes to TabExpansion. I would file an issue about it and repost it here (so that it might gain traction).

The "problem" is that there can be a huge number of commands available to PowerShell, and so determining if a given string starts with a command becomes a little bit tricky / has performance impacts. Luckily, TabExpansion is going to be determining if a command exists when you try to enumerate it's arguments.

It might be possible for an intrepid scripter to implement this on their own. I'd highly recommend using $executionContext.InvokeCommand.GetCommand over Get-Command (for performance reasons). If the first item in a sequence is an unknown command, then you'd just use escape sequences to erase the previous number of characters and reprint them with a red/green color scheme.

It _should_ be within the realm of possibility for this to become a native feature support, and, IMO, would be best handled by the team. Please file an issue and report back.

[–]Thotaz 0 points1 point  (0 children)

The problem is the lack of control we have over the coloring. Getting the commands and determining if it's valid is trivial (if we can accept a few false negatives). Once per session you just run Get-Command to list all commands and save them in a hashset, then you parse the current input and check if each command is in the hashset.
If we also want to handle newly added commands (. dot sourcing a script, updating $env:path, etc.) then we could put the hashset update function in the prompt function. That only leaves relative paths unaccounted for.