Skip to content

daxian-dbw/PSNativeToolCompletion

Repository files navigation

PSNativeToolCompletion

This PowerShell module enables lazy loading of argument completion scripts for native commands. It leverages the new 'fall-back' completer for native commands -- Register-ArgumentCompleter -NativeFallback (introduced in PowerShell v7.6).

When tab completion is triggered for a native command, it checks for a corresponding completion script, loads and registers it on-demand, and then provides completions. It minimizes startup overhead and only loads completion logic as needed.

Managing Completion Scripts

The module exposes two functions to help you manage completion scripts for native commands:

Add-CompletionScript

Adds or updates a completion script for a native command. The script will be stored in ~/.pwsh/completions/ with the naming convention __<command>.ps1.

Syntax:

Add-CompletionScript -Command <string> -InputScript <string>
  • -Command: The name of the native command (e.g., docker, kubectl, gh)
  • -InputScript: The completion script content (accepts pipeline input)

Examples:

Add a completion script generated by a native tool:

docker completion powershell | Add-CompletionScript -Command docker

kubectl.exe completion powershell | Add-CompletionScript -Command docker

gh completion -s powershell | Add-CompletionScript -Command gh

Get-CompletionScript

Lists completion scripts that have been added to the module's completion directory.

Syntax:

Get-CompletionScript [[-Command] <string[]>]
  • -Command: Optional. One or more command names to filter by. If omitted, lists all completion scripts.

Examples:

List all completion scripts:

Get-CompletionScript

Get completion script(s) for specific command(s):

Get-CompletionScript docker
Get-CompletionScript docker, kubectl, gh

View the content of a completion script:

Get-CompletionScript kubectl | Get-Content

Installing latest version from main

Prerequisites

  1. The PSResourceGet module is installed.
  2. A SecretVault is created called default.

Instructions

Setup a PAT to read the feed.

Create a Personal Access Token (Classic) with package:read permission. At the time of writing, this is the only type of token that allows these premissions.

## The command should prompt for the secret.
Set-Secret -Name GitHubPackageRead

Register the Repository. This assumes you called you vault default as described in the prerequisites.

Register-PSResourceRepository `
    -name daxian-dbw `
    -uri https://nuget.pkg.github.com/daxian-dbw/index.json `
    -ApiVersion V3 `
    -CredentialInfo @{ VaultName='default'; SecretName='GitHubPackageRead' } `
    -Trusted

Then, you can install the module:

Install-PSResource -Name PSNativeToolCompletion -Repository daxian-dbw

About

A PowerShell module that enables lazy loading of completion scripts for native commands.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages