Provide a way to exclude cmdlets from some modules from completions in a concrete powershell session · Issue #16747 · PowerShell/PowerShell · GitHub
Skip to content

Provide a way to exclude cmdlets from some modules from completions in a concrete powershell session #16747

Closed

Description

Summary of the new feature / enhancement

As a user I want to configure my powershell profile to exclude completion from certain modules that I'm not using on a given context. For example, as a developer when I'm on a powershell session and type Remove-I for (remove-item) the first result I get on autocompletion is Remove-InitiatorId.

In many scenarios like these, some commands that won't ever be used in this context lead to a poor experience where you need to either type more characters to disambiguate or tab through.

It's great that by default you can get commands from all installed modules for discoverability, but with the growing number of modules it becomes painful to use on a regular session.

To provide an analogy, this is similar to importing all namespaces by default on C#, each type is readily available, but searching through the types becomes much more problematic because they are way more irrelevant types in scope.

Proposed technical implementation details (optional)

Ideally this would be either an allow list or a block list (possibly an allow list), where you can set your preferences for the session via a cmd-let to filter completions to the modules you've defined.

Set-CommandCompletion Microsoft.PowerShell.Utility, Microsoft.PowerShell.Management

That will make only commands in those modules to be considered for completions and you can put this on your $Profile so that it happens every time you create a new session.

Activity

  1. jhoneill commented on Jan 14, 2022

    @jhoneill

    At the very least, prioritizing commands from loaded modules over those in available modules would help.

  2. kasini3000 commented on Jan 14, 2022

    @kasini3000

    I would like to ask a similar question.
    I have developed a multi-process powershell automatic management tool [kasini3000].
    I want to know how to get a powershell with the least functions, the smallest memory footprint, and the smallest powershell without loading most .net dlls. Only powershell engine,
    how should I do it?

  3. MartinGC94 commented on Sep 19, 2022

    @MartinGC94
    Contributor

    You can (mostly) do this today. If you set $PSModuleAutoLoadingPreference = "None" PowerShell won't find commands from modules that haven't been imported so instead of running Set-CommandCompletion Microsoft.PowerShell.Utility, Microsoft.PowerShell.Management to limit completions to commands from those modules you instead use Import-Module Microsoft.PowerShell.Utility, Microsoft.PowerShell.Management to explicitly import the modules you want to use in your session.

  4. theJasonHelmick commented on Aug 2, 2023

    @theJasonHelmick
    Collaborator

    Thank you for the feature suggestion! The WG reviewed this and feels that by having an allow list, could create even more confusion. The above suggestion from MartinGC94 to disable autoloading of the modules would be a benefit -- also note that you can create a custom expansion to filter the results. There are multiple examples on the PSGallery that may be of interest. https://teams.microsoft.com/l/message/19:meeting_OTE4MDhkYzAtMmM0Ni00MjRjLWEwMjEtNTJhOTM1OTZhMTFi@thread.v2/1691007155506?context=%7B%22contextType%22%3A%22chat%22%7D

    Microsoft Teams
  5. MartinGC94 commented on Aug 2, 2023

    @MartinGC94
    Contributor

    Well, this is awkward. I actually have 2 pending PRs to fix this particular issue. One for adding the option to Get-Command: #18955 and another to add commands to manage various completion options: #19518

    I know I was initially against the idea, but I changed my mind after installing some modules that added literally thousands of commands to my command completion, many of which I have no use for when I'm in the shell. In an editor it can also be nice to filter out commands from for example VMware if you are working on a Hyper-V script and vice versa without disabling autoloading of modules.

  6. microsoft-github-policy-service commented on Aug 3, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as declined and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions