So I have a code that generates an executable, and I want to be able to add argument autocompletion on my executable.
I can’t even generate a small and easy example from where I could start from. I have looked into the Register-ArgumentCompleter command, but it seems it’s made for powershell functions and cmdlets. Maybe I could make my exe a cmdlet with some kind of encapsulation, but I am a bit of a noob in powershell so not sure I know what I’m talking about…
If someone could help me set up a basic example, that’d be great !
for example I have an executable called example.exe (don’t care what it does), and when in powershell I run .\example.exe TAB it suggests foo or bar.
That possible ?
Thanks 🙂
I tried this (and more)
$scriptBlock = { 'foo','bar' }
Register-ArgumentCompleter -CommandName .\example.exe -ParameterName Name -ScriptBlock $scriptBlock
.\example.exe TAB
=> that shows just the files in current folder
>Solution :
Ditch the parametername argument. I’d also use just the executable name (if it’s in your path environment variable) or the full path to the executable name.
$scriptBlock = { 'foo','bar' }
Register-ArgumentCompleter -CommandName example.exe -ScriptBlock $scriptBlock
or
$scriptBlock = { 'foo','bar' }
Register-ArgumentCompleter -CommandName full\path\to\example.exe -ScriptBlock $scriptBlock
Now when you type example.exe TAB it will complete with foo/bar
If you don’t want to have to type .exe as well, omit it from the definition
$scriptBlock = { 'foo','bar' }
Register-ArgumentCompleter -CommandName example -ScriptBlock $scriptBlock