ghostty icon indicating copy to clipboard operation
ghostty copied to clipboard

Provide shell ssh integration for nushell

Open dmatos2012 opened this issue 1 month ago • 1 comments

Closes #7877.

Small disclaimer: First Ghostty PR and Zig PR, but looking forward to contributing to the project.

This PR supports shell-integration-features ssh-env and ssh-terminfo as per other shells, but not the rest as this is what the issue states.

That being said, with this PR, then you would see this:

  • warning(io_exec): shell could not be detected, no automatic shell integration will be injected, but given that the default mode is detect it will pick up the executable and if ssh features are enabled it will integrate it. This might be confusing for users.

  • I decided to not add nu to pub const Shell because if we do so, then from what I understand from the code, then the code flow would imply that "shell integration will be injected" but it will only do so if those ssh-* features are enabled, which may be misleading. But on the other hand, providing ssh shell integration but returning null for ?!ShellIntegration does not seem very correct either.

  • I dont like that I added features argument to setupshell, just to check them if nu was used. The reasoning is because the way Nushell works, if we autoload the nushell directory (by setupXdgDatadirs()) even if no ssh features were present, it will wrap the ssh function and I think that is not desirable, even if we end up just forwarding the arguments.

Sorry for the long wall of text, but I think it was worth to add some of the doubts I have had myself, plus the ones that you folks may add. I am very happy to iterate on this, even if its a very "Easy" one, so I much welcome the feedback.

[!NOTE]

Used GPT for helping with nushell variable naming verification/improvement Used Gemini for helping with understanding the Zsh ssh integration so that I could replicate the logic with nushell. Just because I find zsh language very difficult to understand in detail.

dmatos2012 avatar Nov 16 '25 09:11 dmatos2012

Hi @pluiedev thanks for the feedback. I did test it before hand, maybe it was using a cache build? If I do a zig build from main, and checkout my branch and do zig build run its not registered. I have to do first zig build from my branch, and then zig build run, and then its registered in the zig-out/share/.... Did you also enable the ssh features?

Regarding the "strangeness", I ran initially run-external, and forgot about the caret notation, so i stuck with run-external everywhere. Additionally, I tried to follow the zsh approach for the integration, so maybe that plays a part in the "strangeness" that you mention, but thanks, I have addressed your changes!

@rhodes-b correct, I did not know that, I updated the readme to reflect it.

dmatos2012 avatar Nov 18 '25 16:11 dmatos2012

@jparise thanks for super good feedback. I have addressed the changes requested and replied to one of your questions which am also very curious about the best solution.

dmatos2012 avatar Dec 03 '25 21:12 dmatos2012

@jparise I addressed the changes mentioned above, and on top gave it an initial shot on actually checking the features in nushell, and letting zig just set the xdgDataDirs unconditionally. This works now by :

/autoload/vendor/bootstrap-integration.nu -> checks the $env.GHOSTTY_SHELL_FEATURES which decides whether the `ghostty-ssh-integration.nu` file will be sourced or not
/autoload/vendor/source-integration.nu -> sources `ghostty-ssh-integration.nu` if a particular file is present
ghostty-ssh-integration -> Not on autoload anymore, and will only be sourced given conditions above.

There is still a TODO(how to update the ghostty-ssh-integration.nu file on a new release), but wanted first to get the idea out to see what you guys think about it.

For the reasons why we need multiple files and do it this way, is due to how nushell deals with sourcing files and use files. More details on the last commit itself and Parse Constant Time Evaluation

dmatos2012 avatar Dec 05 '25 23:12 dmatos2012