PowerShellEditorServices icon indicating copy to clipboard operation
PowerShellEditorServices copied to clipboard

Provide a way to enable auto-loading of editor command modules

Open daviwil opened this issue 9 years ago • 4 comments

It would be nice if there was a way for the user to opt in to the auto-loading of any PowerShell Gallery modules they've installed which include editor commands written with the new extensibilty model. The user would add a cmdlet call to their chosen editor's profile which invokes this module auto-loading process. It might look something like this:

Import-EditorCommandModules [-Exclude <String[]> [-Repository <String[]>]`

The -Exclude parameter would take a list of module names which should be excluded from the auto-loading process. The -Repository parameter would restrict auto module loading to only the modules which were installed from the specified repositories.

When invoked, this command would use Get-InstalledModule to find all modules and then filter them down to the specified repositories. It'd then filter them down even further to only those with a conventional tag called EditorCommand. This would allow module authors to indicate that their module contains editor commands which can be auto-loaded.

daviwil avatar May 04 '16 05:05 daviwil

Import-EditorCommandModule

Singular noun, ahem. ;)

KirkMunro avatar May 04 '16 12:05 KirkMunro

Clearly I didn't run this issue through PSScriptAnalyzer ;) Though it sounds weird without pluralization. Is there a better noun for this purpose?

daviwil avatar May 04 '16 14:05 daviwil

I think the noun is fine. PowerShell uses Module even though you can import more than one module e.g. Import-Module Pscx, Pester, PSScriptAnalyzer.

RE the tag EditorCommand, should that be a bit more specific perhaps PSESEditorCommand or maybe just PSEditorCommand to avoid accidentally loading non-applicable modules?

rkeithhill avatar May 04 '16 16:05 rkeithhill

Agreed that the noun sounds fine.

I think the proposed command design needs some work though.

If it were me, I would create a Get-EditorExtensionModule command that finds all modules (installed or not -- xcopy deployed modules count) on a system that have editor extensions. That would also make this easy:

Get-EditorExtensionModule | Import-Module

I also wonder about the value of filtering on repository. I just can't think of a use case where I would actually use that. There are better approaches to setting up an environment so that all of the pieces that are used in an organization are in place, updated, and auto-loaded. Happy to discuss this some more anytime.

KirkMunro avatar May 05 '16 19:05 KirkMunro