< Back
Register-BashArgumentCompleter
Post
NAME Register-BashArgumentCompleter
SYNOPSIS
Registers command line completions from bash into PowerShell.
SYNTAX
Register-BashArgumentCompleter [-Command] <String> [-BashCompletions] <String> [<CommonParameters>]
DESCRIPTION
Registers a command line completion that runs in bash so it can be brought into PowerShell. This
is helpful for some commands like "kubectl" that have bash completions supported but where there
is no built-in support for PowerShell.
The command assumes you either have bash in your path or Git for Windows installed. If you don't
have bash in the path then the version packaged with Git for Windows will be used.
If you aren't getting completions, check the following:
- Run with the -Verbose flag to see what the completer is finding.
- Try manually running the completion command that -Verbose outputs using a sample command line.
- Make sure bash is in your path or that you have Git for Windows installed so bash.exe can be found.
PARAMETERS
-Command <String>
The name of the command in bash that needs completions in PowerShell (e.g., kubectl). This is what
PowerShell will get completions on.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-BashCompletions <String>
The full path to the bash completion script that generates completions for the command. You can usually
download this or export it from the command itself.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>This example shows how to use the argument completer with kubectl.
First, export the bash completions from the command:
kubectl completion bash > C:\\completions\\kubectl_completions.sh
Then register your completion with PowerShell:
Register-BashArgumentCompleter kubectl C:\\completions\\kubectl_completions.sh
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>This example shows how to troubleshoot completions using a manual bash command.
First, register the completion with PowerShell and use -Verbose:
Register-BashArgumentCompleter kubectl C:\\completions\\kubectl_completions.sh -Verbose
This will output something like the following:
VERBOSE: bash is not in the path.
VERBOSE: Found bash packaged with git.
VERBOSE: bash = C:\\Program Files\\Git\\bin\\bash.exe
VERBOSE: Starting command completion registration for kubectl
VERBOSE: Completion bridge =
/c/Users/username/Documents/WindowsPowerShell/Modules/PSBashCompletions/1.0.0/bash_completion_bridge.sh
VERBOSE: Bash completions for kubectl = /c/completions/kubectl_completions.sh
VERBOSE: Completion command = &"C:\\Program Files\\Git\\bin\\bash.exe"
"/c/Users/username/Documents/WindowsPowerShell/Modules/PSBashCompletions/1.0.0/bash_completion_bridge.sh"
"/c/completions/kubectl_completions.sh" "<url-encoded-command-line>"
The last line, the completion command, is the interesting bit.
Create a URL-encoded version of the thing you want to complete. For example, this command line:
kubectl c
That shows you want to complete all the "c" commands for kubectl. URL encode that and use %20 for spaces:
kubectl%20c
Now run the completion command with your completion line:
&"C:\\Program Files\\Git\\bin\\bash.exe"
"/c/Users/username/Documents/WindowsPowerShell/Modules/PSBashCompletions/1.0.0/bash_completion_bridge.sh"
"/c/completions/kubectl_completions.sh" "kubectl%20c"
This should generate the list of completions, like:
certificate
cluster-info
completion
config
convert
cordon
cp
create
If instead you see an error, that's what you need to troubleshoot.
RELATED LINKS
SYNOPSIS
Registers command line completions from bash into PowerShell.
SYNTAX
Register-BashArgumentCompleter [-Command] <String> [-BashCompletions] <String> [<CommonParameters>]
DESCRIPTION
Registers a command line completion that runs in bash so it can be brought into PowerShell. This
is helpful for some commands like "kubectl" that have bash completions supported but where there
is no built-in support for PowerShell.
The command assumes you either have bash in your path or Git for Windows installed. If you don't
have bash in the path then the version packaged with Git for Windows will be used.
If you aren't getting completions, check the following:
- Run with the -Verbose flag to see what the completer is finding.
- Try manually running the completion command that -Verbose outputs using a sample command line.
- Make sure bash is in your path or that you have Git for Windows installed so bash.exe can be found.
PARAMETERS
-Command <String>
The name of the command in bash that needs completions in PowerShell (e.g., kubectl). This is what
PowerShell will get completions on.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-BashCompletions <String>
The full path to the bash completion script that generates completions for the command. You can usually
download this or export it from the command itself.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>This example shows how to use the argument completer with kubectl.
First, export the bash completions from the command:
kubectl completion bash > C:\\completions\\kubectl_completions.sh
Then register your completion with PowerShell:
Register-BashArgumentCompleter kubectl C:\\completions\\kubectl_completions.sh
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>This example shows how to troubleshoot completions using a manual bash command.
First, register the completion with PowerShell and use -Verbose:
Register-BashArgumentCompleter kubectl C:\\completions\\kubectl_completions.sh -Verbose
This will output something like the following:
VERBOSE: bash is not in the path.
VERBOSE: Found bash packaged with git.
VERBOSE: bash = C:\\Program Files\\Git\\bin\\bash.exe
VERBOSE: Starting command completion registration for kubectl
VERBOSE: Completion bridge =
/c/Users/username/Documents/WindowsPowerShell/Modules/PSBashCompletions/1.0.0/bash_completion_bridge.sh
VERBOSE: Bash completions for kubectl = /c/completions/kubectl_completions.sh
VERBOSE: Completion command = &"C:\\Program Files\\Git\\bin\\bash.exe"
"/c/Users/username/Documents/WindowsPowerShell/Modules/PSBashCompletions/1.0.0/bash_completion_bridge.sh"
"/c/completions/kubectl_completions.sh" "<url-encoded-command-line>"
The last line, the completion command, is the interesting bit.
Create a URL-encoded version of the thing you want to complete. For example, this command line:
kubectl c
That shows you want to complete all the "c" commands for kubectl. URL encode that and use %20 for spaces:
kubectl%20c
Now run the completion command with your completion line:
&"C:\\Program Files\\Git\\bin\\bash.exe"
"/c/Users/username/Documents/WindowsPowerShell/Modules/PSBashCompletions/1.0.0/bash_completion_bridge.sh"
"/c/completions/kubectl_completions.sh" "kubectl%20c"
This should generate the list of completions, like:
certificate
cluster-info
completion
config
convert
cordon
cp
create
If instead you see an error, that's what you need to troubleshoot.
RELATED LINKS