navi icon indicating copy to clipboard operation
navi copied to clipboard

Add shell widget for PowerShell

Open denisidoro opened this issue 3 years ago • 8 comments

denisidoro avatar Jun 20 '21 15:06 denisidoro

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! :)

welcome[bot] avatar Jun 20 '21 15:06 welcome[bot]

Right, I'm ready to start implementing this! What do I have to implement?

Milo123459 avatar Aug 19 '21 17:08 Milo123459

Cool! If you could port https://github.com/denisidoro/navi/blob/master/shell/navi.plugin.bash to PowerShell it would be awesome!

denisidoro avatar Aug 19 '21 18:08 denisidoro

Will do :)

Milo123459 avatar Aug 19 '21 18:08 Milo123459

This + improved Windows support would be a dream, PowerShell 7 is exceedingly useful.

God-damnit-all avatar Dec 15 '21 00:12 God-damnit-all

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?

God-damnit-all avatar Apr 09 '23 15:04 God-damnit-all

@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 }

lurebat avatar Apr 03 '24 09:04 lurebat