Hyphens in Command Names

Hyphens in Command Names

  • Comments 6

In my previous blog entry, I talked about how Michael Fisher had blogged his intial impressions about PowerShell.

One of the things that Michael did not like was the hyphenated command names.  A discussion about the Pros/Cons of hyphens isn't actionable at this point because we've placed our bets and shipped V1.  Even if there was a compelling argument that convinced me of the errors of my ways, I wouldn't be able to do anything about it.    Changing would break compatibility.

Now that isn't to say, "take it or leave it".   No no no no.  This is a customizable shell.  In fact, it is an EASILY customizable shell.  (There's a difference between those 2).

Michael - I encourage you to see if you can come to terms with the our hyphens.  I'm told that everyone blanches the first time they taste Scotch but if you give it chance, you can grow a deep and profound appreciation for it.  On the other hand, if you are like me and hate the stuff (me=>Scotch, you=>hyphenated commands) after repeated attempts to "see the magic", all you need to do is to put the following line in your startup profile:

Get-Command -Type Cmdlet | %{ Set-Alias ($_.Name -replace "-" ) $_.Name}

Give that a try and see how you like it.  If you want to see what is going on, just add a -Verbose to the Set-Alias:

PS> Get-Command -Type Cmdlet |%{Set-Alias ($_.Name -Replace "-") $_.Name -verbose}
VERBOSE: Performing operation "Set Alias" on Target "Name: AddContent Value: Add-Content".
VERBOSE: Performing operation "Set Alias" on Target "Name: AddHistory Value: Add-History".
VERBOSE: Performing operation "Set Alias" on Target "Name: AddMember Value: Add-Member".
VERBOSE: Performing operation "Set Alias" on Target "Name: AddPSSnapin Value: Add-PSSnapin".
VERBOSE: Performing operation "Set Alias" on Target "Name: ClearContent Value: Clear-Content".
VERBOSE: Performing operation "Set Alias" on Target "Name: ClearItem Value: Clear-Item".
VERBOSE: Performing operation "Set Alias" on Target "Name: ClearItemProperty Value: Clear-ItemProperty".
VERBOSE: Performing operation "Set Alias" on Target "Name: ClearVariable Value: Clear-Variable".
VERBOSE: Performing operation "Set Alias" on Target "Name: CompareObject Value: Compare-Object".
VERBOSE: Performing operation "Set Alias" on Target "Name: ConvertFromBase64 Value: ConvertFrom-Base64".

.......

Be aware that if you write scripts using these aliases, you won't be able to share them with other people and have them "just work".  That is the tension between customization and community.  You are empowered to make your own decision about how to resolve that tension. 

Welcome to the community Michael - keep on blogging! 

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

 

Leave a Comment
  • Please add 8 and 3 and type the answer here:
  • Post
  • So can you at least give some supporting rationale for why you chose that hyphens, for those of us feel it makes the language taste like Scotch? (I've never liked Scotch, and it's never grown on me. ;-)

  • > So can you at least give some supporting rationale for why you chose that hyphens,

    It's been a LONG time since we made that decision so I might forget some of the reaons.  I believe that the primary reason was that we wanted to be super hardcore about establishing in everyones mind that there was a VERB and a NOUN.  

    You'll see this when you write a Cmdlet, you have to provide 2 parameters - the VERB and the NOUN.  VMS DCL uses a space seperator between the VERB and the NOUN which I considered for a while because it is easy, plesant on the eyes and consistent with some existing commands (e.g. the NOUN VERB model of NET USE/NET VIEW ).  The problem with this approach comes when you think out the situation in the context of the entire ecosystem where multiple sources provide verbs to the same NOUN.  Seperating them with a space means that the engine has  to do the multiplexing which means that we have to run a registration process.  We already have a registration process but the issue here is that the granularity and semantics of the things you register and the strength of the disambiguation provided by the registration determine what level the ecosystem can integrate with and thus the behavior of the ecosystem.

    VMS is a wonderful system but, in my opinion, we got this part wrong and the DCL registration process ended up driving a behaviour were we ended up with a mixture of VERB NOUN and NOUN VERB commands.  

    Jeffrey Snover [MSFT]

    Windows PowerShell/MMC Architect

    Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell

    Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

  • Jeffrey,

    I understand all the arguments and the reasons why it cannot be changed. I also understand that I can customize my own environment. Unfortunately, as you pointed out, scripts might not work. Also, if I am in some remote location fixing someones machine, I really need to know and use the default names.

    I do like single malt scotch(The Glenlivet) but I will be cursing the hyphen decision for a long time.

    I am going to continue writing about my initial impressions of PowerShell from my point of view, which is a relative novice. I'm glad that someone is listening.

    Unfortunately, due to my nature, most of the things I talk about are going to be things I don't like. If something works as expected I usually don't mention it. If something works surprisingly well, I will mention it.

    -Mike

  • I tried your one-liner to remove the hyphen and there is another undesireable side effect.

    Command line completion doesn't work on the renamed cmdlets.

  • > Unfortunately, due to my nature, most of the things I talk about are going to be things I don't like. If something works as expected I usually don't mention it. If something works surprisingly well, I will mention it.

    No worries.  It is great to hear when people like PowerShell but what helps move the ball forward is when people tell us about the things they don't like or the things that we can do to make it better.  

    > Command line completion doesn't work on the renamed cmdlets.

    Correct.  Tab Completion is just a user-defined script so you can change the behavior to make it do anything you want to.  I use MOW's ( http://thepowershellguy.com/ )TAB Completion.  If you want to tweak a routine - I would start with his.

    Jeffrey Snover [MSFT]

    Windows PowerShell/MMC Architect

    Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell

    Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

  • As Jeffrey metioned (tanks ;-)) my tabcompletion can help with this.

    1 Aliases are expanded,

    2 functions are also tabcompleted

    3 you can start tabcompletion before the dash -by using the percent % sign

    4 GUI tabcompletion  c_im [tab]

    and much more,

    I just made a new version You can find the latest version (including installer) here :

    http://thepowershellguy.com/blogs/posh/pages/powertab.aspx

    just download the PowerShell.zip, extract and run PowerTabSetup.ps1

    I did not add a partial completion on aliases yet but you can add them to the Function expansion, I did not yet include a utilityscript for that ( Custum partial completion ) but al functionality is available

    also I'm working on a blogentry about this new version with more info.

    Enjoy,

    Greetings /\/\o\/\/

Page 1 of 1 (6 items)