navi
navi copied to clipboard
Add shell widget for PowerShell
Thanks for opening your first issue here! In case you're facing a bug, please update navi to the latest version first. Maybe the bug is already solved! :)
Right, I'm ready to start implementing this! What do I have to implement?
Cool! If you could port https://github.com/denisidoro/navi/blob/master/shell/navi.plugin.bash to PowerShell it would be awesome!
Will do :)
This + improved Windows support would be a dream, PowerShell 7 is exceedingly useful.
Right, I'm ready to start implementing this! What do I have to implement?
Is this still on your bucket list, or do you no longer have the time?
@denisidoro
I don't have the time to make a full PR, but here is a powershell script adapted from the fish script:
function Invoke-NaviWidget {
$ast = $tokens = $errors = $cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $ast, [ref] $tokens, [ref] $errors, [ref] $cursor)
$line = $ast.ToString().Trim()
$output = $null
if ([String]::IsNullOrEmpty($line)) {
$output = navi --print
}
else {
$best_match = (navi --print --best-match --query $line | Out-String).Trim()
if ([String]::IsNullOrEmpty($best_match)) {
$output = (navi --print --query "$line" | Out-String).Trim()
} else {
$output = $best_match
}
}
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($output)
}
Set-PSReadlineKeyHandler -Key Ctrl+g -ScriptBlock { Invoke-NaviWidget }