Sunday, January 11, 2009

Powerless Completion in PowerShell

PowerShell has command line completion. It can complete cmdlets, arguments, methods, properties and probably many more things. Which is great. But because this is Windows, there just has to be something terribly wrong with it...

Command Line Completion Essentials

Completion can be provided for a lot of things, but there are two for which I consider completion to be essential:

  • commands (programs)
  • files and directories

Lets look how the completion of these two essential things is handled in PowerShell.

Program Name Completion

It seems natural, that when we have a command line completion, then we should be able to complete commands. PowerShell doesn't think so. Completion is only provided for the PowerShell-native cmdlets. But simple executable programs are not worthy to receive the mighty PowerShell completion. Completion also doesn't work with aliases.

Actually the completion doesn't even work well with PowerShell cmdlets. For example there is cmdlet Join-Path, which is the only cmdlet starting with letter J. One would think that you just type "J", press TAB and have it completed to "Join-Path". Yeah... but not in PowerShell. Instead you have to type "Join-" and only after that you can press TAB to have it completed.

But as I said in my previous post, in Windows real programs aren't available from command line anyway - so I guess it makes sense to not have completion for these things also.

Filename Completion

But what about filename completion. It did work reasonably well in cmd.exe. It clearly must also work in PowerShell. Well... sort of.

Suppose that you open cmd.exe and want to go to your Desktop directory. You are already in your home directory, so you just type cd and the letter d:

C:\Documents and Settings\Rene>cd d

Then you press TAB and it will be completed to:

C:\Documents and Settings\Rene>cd Desktop

This works the same way in PowerShell. But suppose you want to go two directories with a one step. Suppose you want to go to Desktop\MyDir. So you just type backslash and letter m:

C:\Documents and Settings\Rene>cd Desktop\m

Then you press TAB again and in cmd.exe it will be completed to:

C:\Documents and Settings\Rene>cd Desktop\MyDir

But in PowerShell this will be completed to:

PS C:\Documents and Settings\Rene> cd 'C:\Documents and Settings\Rene\Desktop\MyDir'

PowerShell might call this a feature, but I would certainly call this a regression.

Just Another Day in Windows

PowerShell is nice. In fact it's even quite cool. But like always with Microsoft, they managed to screw up the essentials.

2 comments:

  1. Thanks for the feedback. Much of this behaviour has been improved in the latest CTPs of PowerShell V2. You can get CTP3 from here: http://blogs.msdn.com/powershell/archive/2008/12/23/early-christmas-present-from-powershell-team-community-technology-preview-3-ctp3-of-windows-powershell-v2.aspx.

    Hope this helps,
    Lee Holmes [MSFT]
    Windows PowerShell Development

    ReplyDelete
  2. Thanks Lee Holmes.

    I upgraded to PowerShell V2 CTP3 and it indeed fixes all the complaints listed here.

    ReplyDelete