mirror of
https://github.com/denisidoro/navi.git
synced 2026-01-23 02:14:19 +00:00
Add initial powershell plugin by @lurebat
Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com>
This commit is contained in:
parent
089be801b2
commit
4a8b4b707c
1 changed files with 26 additions and 0 deletions
26
shell/navi.plugin.ps1
Normal file
26
shell/navi.plugin.ps1
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
### Initial code from @lurebat (https://github.com/lurebat/)
|
||||
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 }
|
||||
Loading…
Add table
Add a link
Reference in a new issue