Skip to content

Conversation

@twobiers
Copy link

@twobiers twobiers commented Jul 8, 2022

Resolves #344

I have tried to implement an equivalent Tab completion for PowerShell, which was to some point successful.
It works like the following:

  • Use the default directory completion when no arguments are provided
  • If an argument is provided, use it as zoxide query input

Unfortunately it doesn't seem to be possible to run interactive queries in PowerShell within the argument completer, therefore I don't know whether it is possible to implement the "space+tab" completion.
Also I am unsure what should happen if mutliple arguments are provided. At the moment the tab completion ignores that and happily completes the second argument. For example z dir1 dir2 would try to complete dir2 to z dir1 P:/tmp/dir2.

Maybe it would be useful to also add the default completions into the completions, so that I could use z as a cd replacement.

Please let me know your thoughts.

This GIF shows, how it works:
WindowsTerminal_caWG2ym896

@ajeetdsouza ajeetdsouza deleted the branch ajeetdsouza:next February 20, 2024 22:23
@ajeetdsouza
Copy link
Owner

Hey, looks like this PR got closed by accident because we moved from next back to main (it was causing quite a bit of confusion, we started seeing PRs to both next and main). Sorry about that!

I tried out a rudimentary completer, this seems to work fine on pwsh 7.5.1 / macOS (although I don't know if it would work on Windows):

Register-ArgumentCompleter -Native -CommandName z -ScriptBlock {
    param(
        $WordToComplete,
        $CommandAst,
        $CursorPosition
    )
    $result = zoxide query -i
    Set-Location $result

    # Clear the current line
    [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
    [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
}

The way completions are done in other shells is:

  • if the user is completing their first arg (or if there are no args), we use regular cd completions
  • if the user presses Space+Tab (that means there are one or more args, and they have started a fresh arg), we use interactive completions

Would you be able to create a fresh PR that matches the behavior of existing shells?

@twobiers
Copy link
Author

Hi @ajeetdsouza Thanks for coming back to this. I'm not actively using windows anymore either, but can still try to test it again. Your proposed behavior is actually the same implemented (See the GIF). If you can change the target of this PR to main and reopen the PR, we can just reuse this one. If that's not possible, I can also create a fresh one.

@ajeetdsouza
Copy link
Owner

ajeetdsouza commented May 13, 2025

Sadly, I'm not able to change the target either, so a fresh PR would be great.

@twobiers
Copy link
Author

I think you would have to reopen the pull request to do so as targets can only changed on opened PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tab completions for PowerShell

2 participants