From b236763df53c5eca518081b3dad10dc44efb08d9 Mon Sep 17 00:00:00 2001 From: kirinnee Date: Mon, 18 May 2020 11:19:00 +0800 Subject: [PATCH 1/2] Added manual and script for PowerShell autocomplete --- autocomplete/powershell_autocomplete.ps1 | 9 +++++++++ docs/v2/manual.md | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 autocomplete/powershell_autocomplete.ps1 diff --git a/autocomplete/powershell_autocomplete.ps1 b/autocomplete/powershell_autocomplete.ps1 new file mode 100644 index 0000000000..81812a6a43 --- /dev/null +++ b/autocomplete/powershell_autocomplete.ps1 @@ -0,0 +1,9 @@ +$fn = $($MyInvocation.MyCommand.Name) +$name = $fn -replace "(.*)\.ps1$", '$1' +Register-ArgumentCompleter -Native -CommandName $name -ScriptBlock { + param($commandName, $wordToComplete, $cursorPosition) + $other = "$wordToComplete --generate-bash-completion" + Invoke-Expression $other | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } + } \ No newline at end of file diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 55008b4b55..63d3bc375a 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -1222,6 +1222,23 @@ source path/to/autocomplete/zsh_autocomplete #### ZSH custom auto-complete example ![](/docs/v2/images/custom-zsh-autocomplete.gif) +#### PowerShell Support +Auto-completion for PowerShell is also supported using the `autocomplete/powershell_autocomplete.ps1` +file included in this repo. + +Rename the script to `.ps1` and move it anywhere in your file system. +The location of script does not matter, only the file name of the script has to match +the your program's binary name. + +To activate it, enter `& path/to/autocomplete/.ps1` + +To persist across new shells, open the PowerShell profile (with `code $profile` or `notepad $profile`) +and add the line: +``` +& path/to/autocomplete/.ps1 +``` + + ### Generated Help Text The default help flag (`-h/--help`) is defined as `cli.HelpFlag` and is checked From 9523a3481bf492de121be67a254086b0404d1ade Mon Sep 17 00:00:00 2001 From: kirinnee Date: Mon, 8 Jun 2020 10:54:27 +0800 Subject: [PATCH 2/2] Updated Docs Header in table of content for PowerShell support --- docs/v2/manual.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/v2/manual.md b/docs/v2/manual.md index 63d3bc375a..951384e7c7 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -30,6 +30,7 @@ cli v2 manual + [ZSH Support](#zsh-support) + [ZSH default auto-complete example](#zsh-default-auto-complete-example) + [ZSH custom auto-complete example](#zsh-custom-auto-complete-example) + + [PowerShell Support](#powershell-support) * [Generated Help Text](#generated-help-text) + [Customization](#customization-1) * [Version Flag](#version-flag)