-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update PowerShell plugin #947
Conversation
Signed-off-by: alexis-opolka <[email protected]>
Signed-off-by: alexis-opolka <[email protected]>
https://github.com/alexis-opolka/navi.plugin.pwsh Signed-off-by: alexis-opolka <[email protected]>
Signed-off-by: alexis-opolka <[email protected]>
@kit494way, I won't be able to test if the fix is effective or not until next monday, if you need to do not hesitate to grab my version of navi on the |
@alexis-opolka I have not tried to run the command because I do not have an environment that can build a binary for windows.
If separating the widget into a third-party module, I think it is enough to describe the installation instruction in a document like the widget for xonsh. Lines 130 to 132 in 90a29ed
If installing the 3rd party module that is not managed by this project, it is better to notify users about it. |
Then it will wait before I can use a windows system to compile and see. Since widgets are integrating with 3rd-party, it might not have to be necessarily tied to a given Navi's version. I don't know if it's actually a good idea to have the PowerShell module separated from navi, I did this PR as a quick fix but now that you raised some good points, I need to think about it. 🤔 |
After some more thoughts @kit494way , it would indeed be good for navi to have the command print out the PowerShell module but I think it would somewhat go against PowerShell's philosophy with integrating 3rd-party modules. I think that we can do it in two different ways. The first one would be to continue to treat the powershell plugin as an internal dependency of the project and modify the installation process by printing out the module's code, which would then be called inside the user's profile. The second one would be to treat the powershell plugin as an external dependency of the project and remove its code from navi, the installation process would be similar to the xonsh module. The pros of the first would be the linked versioning of both navi and its powershell plugin. The cons would be to have an update of navi even when navi's code might be unchanged. The pros of the second would be the logical separation of the powershell plugin with navi which enables us to have more flexibility on their versions i.e. we're not obligated to create an update of navi to fix the powershell plugin. The cons would be the break of the linked versioning, two users with Navi 2.24.0 can have a different behaviour with the powershell plugin. What do you think? |
@alexis-opolka I expect shell widgets to serve two roles.
On the second point, I prefer to output the function definitions, because I can easily see how the widget is implemented. Although I am not familiar with powershell's philosophy, I know of two precedents that output function or module definitions, starship and mise. If the module is to be separated into external module, it would be better to output the version of the module, and it would be nice to be able to easily see where the source of the module is found. |
I agree with you @kit494way , I'll make the necessary modifications during the weekend if I'm able to, otherwise it will need to wait until next week. |
I'm going to update the command to output the module definition and I do think that your suggestions are a better way for the project, thanks! 😄 |
This reverts commit 2bb57a2.
It should remove the need to put a "-" in the middle of the name. It's a bit impractical.
Updated the link to the module.
Moves the file to the base folder, removed cmdlets handlers and related options. Still needs modifications.
Signed-off-by: alexis-opolka <[email protected]>
Signed-off-by: alexis-opolka <[email protected]>
It should be good on my side @kit494way , this version should print out the module's definition and not issue any problems while trying to invoke the powershell plugin. |
@alexis-opolka diff --git a/shell/navi.plugin.ps1 b/shell/navi.plugin.ps1
index c931357..a99592c 100644
--- a/shell/navi.plugin.ps1
+++ b/shell/navi.plugin.ps1
@@ -1,6 +1,21 @@
$null = New-Module {
+ function Invoke-Navi {
+ $p = [System.Diagnostics.Process]@{StartInfo = @{
+ FileName = "navi";
+ Arguments = $args;
+ RedirectStandardOutput = $true;
+ WorkingDirectory = $PWD;
+ }}
+
+ [void]$p.Start()
+ $result = $p.StandardOutput.ReadToEnd()
+ $p.WaitForExit()
+
+ $result
+ }
+
### Initial code from @lurebat (https://github.com/lurebat/)
### See #570 (https://github.com/denisidoro/navi/issues/570) for its original contribution
function Invoke-NaviWidget {
@@ -11,12 +26,13 @@ $null = New-Module {
$output = $null
if ([String]::IsNullOrEmpty($line)) {
- $output = navi --print
+ $output = (Invoke-Navi "--print" | Out-String).Trim()
}
else {
- $best_match = (navi --print --best-match --query $line | Out-String).Trim()
+ $best_match = (Invoke-Navi "--print" "--best-match" "--query `"$line`"" | Out-String).Trim()
+
if ([String]::IsNullOrEmpty($best_match)) {
- $output = (navi --print --query "$line" | Out-String).Trim()
+ $output = (Invoke-Navi "--print" "--query `"$line`"" | Out-String).Trim()
}
else {
$output = $best_match
@@ -24,6 +40,7 @@ $null = New-Module {
}
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
+ [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
### Handling the case when the user escapes without selecting any entry
if (-Not([String]::IsNullOrEmpty($output))) { |
Co-authored-by: KITAGAWA Yasutaka <[email protected]> Signed-off-by: alexis-opolka <[email protected]>
Signed-off-by: alexis-opolka <[email protected]>
Signed-off-by: alexis-opolka <[email protected]>
@kit494way It should work correctly now. Just a quick update though, the subcommand for the powershell plugin is not EDIT: In the case of a squash, please make sure that kit494way is mentioned as co-author of the commit. |
Signed-off-by: alexis-opolka <[email protected]>
This PR intends to fix #946 by removing any relative path used in the install and to do so the PowerShell module
has been moved to its own repository (https://github.com/alexis-opolka/navi.plugin.pwsh)is now printed as-is and can then be "evaled" in a profile or in the session.