Skip to content

A PSReadLine Predictor which uses zoxide under the hood

License

Notifications You must be signed in to change notification settings

schnow265/ZoxidePredictor

Repository files navigation

ZoxidePredictor

This is an experimental PSReadLine predictor using zoxide results to show you what folder you are about to cd into - before you press enter.

Note: This module currently has the zoxide command fixed to cd.

You can set the zoxide alias to cd by replacing the zoxide init line in your $PROFILE with this

Invoke-Expression (& { (zoxide init powershell --cmd cd | Out-String) })

How does this work?

  1. Every 60 seconds a background thread activates which will run zoxide query --list --all --score and parses the result into an in-memory dictionary.
  2. Does nothing until you type cd (note the space at the end) just like you would with zoxide.
  3. This module then sorts prediction results using a C# Reimplementation of the zoxide algorithm to the shell to show up as suggestions The Predictor in action

Installation

Dependencies

Build & Install

  1. Clone this repo
  2. Enter the Subdirectory ZoxidePredictor
  3. Run (best in PowerShell):
    # non-Windows
    dotnet publish -c Release -o $HOME/.local/share/powershell/Modules/ZoxidePredictor
    
    # Windows
    dotnet publish -c Release -o $HOME\Documents\PowerShell\Modules\ZoxidePredictor
  4. Add the following to your $PROFILE:
    Import-Module ZoxidePredictor
  5. Restart powershell and verify that the provider has been registered by running Get-PSSubsystem -Kind CommandPredictor, which should have zoxide under Implementations

Bonus Tip:

Press <F2> to switch between inline and list. (I personally prefer list).

To permanently change to list by default, add the following line to your $PROFILE:

Set-PSReadLineOption -PredictionViewStyle ListView

(You may also need to add Import-Module PSReadLine at the top. On some systems I need it, on others not.)

TODO

These are things still to do:

  • Add build workflow
  • Add Tests (where possible)
  • if any of my other projects require it: Extract Matcher.cs into a seperate project and maintain the implementation properly there
  • Find a way to do ci/cd releases on tags to PSGallery for easier installation

About

A PSReadLine Predictor which uses zoxide under the hood

Topics

Resources

License

Stars

Watchers

Forks

Languages