1

I am playing with ICommandPredictor, a way to create powershell predictor in C#

My goal is to show as suggestion the list of available git branch in the current directory, and by current directory I mean : "the location where is the shell calling the predictor"

But I cannot find a way to get it.

I tried Environment.CurrentDirectory, Directory.GetCurrentDirectory() but it always return the starting location of the shell. I also played a bit with GetPSSubsystemCommand and SubsystemManager but not luck for now.

I'm starting to think it is not possible to get this data.

Ashijo
  • 90
  • 8
  • See following : https://learn.microsoft.com/en-us/powershell/scripting/samples/collecting-information-about-computers?force_isolation=true&view=powershell-7.3 – jdweng Mar 14 '23 at 09:09
  • 1
    I'm sorry, but I don't see at all how this can help me. Are you sure you pasted the good link ? – Ashijo Mar 14 '23 at 16:55
  • Yes. The command predictor is under the Managing Computers. I used you link and went up a few levels and found my link. – jdweng Mar 14 '23 at 19:19
  • Looking at the APIs I don't see a way to do this either, curiously. It's worth opening an issue at https://github.com/PowerShell/PowerShell/issues – mklement0 Mar 14 '23 at 22:44
  • @jdweng, doubling down with a non sequitur after having been told that your comment is unhelpful is even more unhelpful. – mklement0 Mar 14 '23 at 22:46
  • Note that if you're looking for custom tab-completions _for a given command_, say `git`, using [`Register-ArgumentCompleter`](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/register-argumentcompleter) is sufficient. See [this answer](https://stackoverflow.com/a/54945469/45375) for an example. – mklement0 Mar 14 '23 at 23:29
  • @mklement0 Thanks for the suggestion, but I'd like to choose in a menu style, using arrow key to select an option. Another idea if this isn't possible would be to create a console app with spectre... – Ashijo Mar 20 '23 at 16:44
  • 1
    @Ashijo, if you place `Set-PSReadLineKeyHandler Tab MenuComplete` in your `$PROFILE`, you'll get menu-style tab-completion. – mklement0 Mar 20 '23 at 16:51
  • 1
    @mklement0 It works :D just what I needed. Thank you. I have still created a feature request for powershell because I think predictors are cool, and should be improved. – Ashijo Mar 22 '23 at 17:42

0 Answers0