vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Auto expansion for alias commands.

Open ww40 opened this issue 9 years ago • 21 comments

A common factor in providing help and reviewing PowerShell scripts in general we find veterans who will use alias's for common commands such as %(ForEach-Object), cls(Clear-Host), ri(Remove-Item), mi(Move-Item, CD(Set-Location)....I'm sure you see where i'm going with this.

What if upon saving your solution there would be an option to automatically convert all the alias commands into their full commands to save time on converting documents into more readable documents for future use/reviews.

Could this be something you could implement?

ww40 avatar Feb 09 '17 13:02 ww40

We could definitely enable "expand aliases on save" and put it behind a setting so that it can be turned on per-workspace.

daviwil avatar Feb 09 '17 14:02 daviwil

@kapilmb wanna give this a shot for 0.11.0?

daviwil avatar Feb 09 '17 14:02 daviwil

This looks like a special case of #417. Sure, we can get target it for 0.11.0.

kapilmb avatar Feb 09 '17 18:02 kapilmb

Please do not enable it by default. I think this needs to be "opt-in".

rkeithhill avatar Feb 09 '17 18:02 rkeithhill

Yeah, enabling by default would not be the desired behavior.

daviwil avatar Feb 09 '17 18:02 daviwil

It might be nice to allow configuration to include or exclude aliases from this expansion. I know several people in the community who are against expanding *-object aliases (i.e. select, where)

eweilnau avatar Feb 09 '17 18:02 eweilnau

Luckily Kapil has already satisfied your request :)

https://github.com/PowerShell/PSScriptAnalyzer/blob/development/RuleDocumentation/AvoidAlias.md#alias-whitelist

daviwil avatar Feb 09 '17 18:02 daviwil

Might be worth having a blacklist too, though. A whitelist will be harder to maintain.

daviwil avatar Feb 09 '17 18:02 daviwil

several people in the community who are against expanding *-object aliases

I was one of those folks until PowerShell went cross platform where sort is a native util and PowerShell Core does not provide sort as an alias to Sort-Object. Now I'm firmly in the camp of expanding *-Object.

rkeithhill avatar Feb 09 '17 18:02 rkeithhill

I see this as part of (or at least similar to) formatting in which more configuration is better because consensus is (nearly) impossible.

eweilnau avatar Feb 09 '17 18:02 eweilnau

I just wish tab-expansion would offer to change cd to Set-Location...

Jaykul avatar Feb 13 '17 18:02 Jaykul

@Jaykul: what would be the desired flow for that? You type cd and you get Set-Location as a completion option? Or you type cd and hit tab and it turns into Set-Location?

daviwil avatar Feb 13 '17 18:02 daviwil

For me, the completion option by default and a setting to enable the tab turns into on/off.

jagrock avatar May 10 '17 22:05 jagrock

I would make the original request into something more broad, where you run an entire set of customizable PSScriptAnalyzer rules against the entire VSCode workspace, triggered by certain events (eg. Files: Save All). The PowerShell extension could have a configurable setting to point to the path of an array of PSScriptAnalyzer rule manifests, relative to the workspace path.

pcgeek86 avatar May 17 '17 15:05 pcgeek86

Hi all,

Has this been released? If not is there a date?

RickFlist avatar Sep 01 '17 16:09 RickFlist

@RickFlist try the "PowerShell: Expand Alias" command, that should work for now.

daviwil avatar Sep 01 '17 17:09 daviwil

That's what I'm using now. Thanks

RickFlist avatar Sep 01 '17 18:09 RickFlist

Doing some issue clean up. How are we feeling about this? Are we at a point where we can close it? The "PowerShell: Expand Alias" command works really well.

Or are we interested in an opt-in feature to turn on expanding aliases on save?

TylerLeonhardt avatar Dec 08 '17 00:12 TylerLeonhardt

@tylerl0706 bigger fish to fry at the moment. I'd say close it.

pcgeek86 avatar Dec 08 '17 00:12 pcgeek86

Some people want this feature. Just set it to false by default, but give people the option to enable it. We already have "editor.formatOnSave"-- why not add "editor.expandAliasOnSave"?

nlupica1 avatar May 04 '18 20:05 nlupica1