mirror of
https://github.com/denisidoro/navi.git
synced 2026-01-23 02:14:19 +00:00
Create navi.plugin.psm1
Moves the file to the base folder, removed cmdlets handlers and related options. Still needs modifications.
This commit is contained in:
parent
cc1187e259
commit
7a2108cb20
1 changed files with 30 additions and 0 deletions
30
shell/navi.plugin.psm1
Normal file
30
shell/navi.plugin.psm1
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
### Initial code from @lurebat (https://github.com/lurebat/)
|
||||
### See #570 (https://github.com/denisidoro/navi/issues/570) for its original contribution
|
||||
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()
|
||||
|
||||
### Handling the case when the user escapes without selecting any entry
|
||||
if (-Not([String]::IsNullOrEmpty($output))) {
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::Insert([String]$output)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue