-
Notifications
You must be signed in to change notification settings - Fork 895
Add SSH Integration Configuration Option #7608
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
base: main
Are you sure you want to change the base?
Conversation
src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish
Outdated
Show resolved
Hide resolved
src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish
Outdated
Show resolved
Hide resolved
src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish
Outdated
Show resolved
Hide resolved
Also I think we should consider an approach that might be less intrusive for the user. I find how Kitty does it to be pretty ingenious, but since it's GPL code we can't look at it exactly. We can definitely still try to piece it together just through the broad-picture description, though. |
@pluiedev I completely agree about Kitty's approach. I see this PR as an interim solution to address the immediate pain points people are hitting (terminfo compatibility, basic env propagation) while a more comprehensive solution gets designed and implemented. Something like Ghostty's equivalent of |
I'm against including this as a part of the main config/executable. |
I haven't decided which approach I prefer, but I also see advantages in the ... and then we could just have another shell integration feature flag ( |
I personally feel that @jcollie could you point me to examples of those alternate main functions? I'm willing to take a shot at it, just want to be realistic about timeline since I'm still learning both Zig and the codebase. That said, this shell integration approach does solve the immediate pain points users are hitting today. If there's value in getting users unstuck while the proper solution gets built, I'm happy to keep iterating on this too. |
https://github.com/ghostty-org/ghostty/tree/main/src/cli :). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason I can't test it myself (not sure why; the shell integration script doesn't seem to be sourced when I run off a git clone 🤔), but how does ssh-integration
play with shell-integration = none
?
Edit: and it works this time, okay then. It seems like shell-integration = none
means ssh-integration
is ignored, not sure if that's wanted.
src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish
Outdated
Show resolved
Hide resolved
src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish
Outdated
Show resolved
Hide resolved
src/shell-integration/fish/vendor_conf.d/ghostty-shell-integration.fish
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on. Overall this is looking really good, thank you. And thank you for addressing prior feedback.
I think the only thing I'm personally hung up on is if this should be its own config or it should be part of shell-integration-features
. My initial proposal you linked had augmenting the prior config in mind.
That's fairly bikeshed and I can figure it out myself. The hard work of making this work across shells you did and I love that.
Okay had some extra time this morning so I read the other feedback. @pluiedev @jcollie I agree that we should have a I'd love to see a |
@mitchellh You're welcome, I'm very happy to help! Thank you so much for weighing in and for the support. Really appreciate you taking the time to review this, and I'm glad the cross-shell work is useful. I'm excited about the potential for Since I'm planning to switch from progressive options to flags anyway based on the extensibility feedback, I'd be happy to implement that under whichever config location you think is most appropriate. I'm actually leaning towards |
Try setting the resources directory explicitly for your local build:
Good catch on the |
Actually it seems to work just fine now, I'm not sure what changed. I'm not complaining I guess ¯\_(ツ)_/¯. |
Does the environment variable propagation actually work? They're not set on the remote for me. |
Ah shoot, yeah... the environment variable propagation seems to be broken. I can confirm that |
If I remember correctly, you need to tell SSH to propagate it in your SSH configuration, and also allow it to be set in the remote's SSH configuration too. And |
23a9867
to
f51007d
Compare
Sorry for the commit spam.. tired brain screwed up a rebase. The actual change is in 0795681 |
Oh also, maybe Maybe |
I think we should focus on the configuration aspect for a bit before getting deeper into the details of the implementation, which could change as a result. I don't yet have strong feelings about using Regardless of the configuration option name, I think we're talking about at least two flags (prefixed with
In practice, I don't know if we need to differentiate forwarding "only (fixed) I'm also not sure we should forward Lastly, I don't love the amount of code that the host-level caching adds to each of the shell integration scripts. If that's truly what it takes to correctly implement this feature, then I'm much more inclined to prefer just an |
I agree with all of @jparise's feedback. |
Works for me! Here are my thoughts:
@jparise, @mitchellh, does this all sound agreeable? |
- Fix elvish function name mismatch and use conj for list operations - Simplify terminfo installation command per ghostty docs (tic -x -) - Fix conditional structure to ensure error messages always print - Remove redundant checks and optimize array initialization - Use consistent patterns across bash, fish, elvish, and zsh implementations
…tions - Cache known hosts with terminfo in $GHOSTTY_RESOURCES_DIR/terminfo_hosts - Skip installation step for cached hosts (single connection instead of two) - Use secure file permissions (600) and atomic writes - Extract SSH target safely from command arguments - Maintains full functionality while improving user experience on repeated connections
Need a sanity check on this new approach for "full" to help determine if it's worth additional iteration/refinement. It solves the double auth issue, successfully propagates env vars, and avoids output noise for connections that happen after terminfo is installed. The only issue I don't have time to fix tonight is the fact that it drops the MOTD for cached (re)connections.
…ration-features flags - Add ssh_env and ssh_terminfo flags to ShellIntegrationFeatures - Remove SSHIntegration enum and ssh-integration config option - Update setupFeatures to handle new flags via reflection - Remove setupSSHIntegration function and all references Integrates SSH functionality into existing shell-integration-features system for better consistency and user control.
Rewrote shell functions to support the two new flags for shell-integration-features: - ssh-env: TERM compatibility + best effort environment variable propagation (anything beyond TERM will depend on what the remote host allows) - ssh-terminfo: automatic terminfo installation with control socket orchestration - Flags work independently or combined Implementation optimizations: - ~65% code reduction through unified execution path - Eliminated GHOSTTY_SSH_INTEGRATION environment variable system - Replaced complex function dispatch with direct flag detection - Consolidated 4 cache helper functions into single _ghst_cache() utility - Simplified control socket management (removed multi-step orchestration) - Subsequent connections to cached hosts are now directly executed and more reliable New additions: - If ssh-terminfo is enabled, ghostty will be wrapped to provide users with convenient commands to invoke either of the two utility functions: `ghostty ssh-cache-list` and `ghostty ssh-cache-clear`
Add ssh-env and ssh-terminfo fields to existing setupFeatures tests.
Addresses feedback about separation of concerns in shell integration scripts. Extracts host caching logic to `src/shell-integration/shared/ghostty-ssh-cache` and updates all four shell integrations to use the shared script. The `shared/` subdirectory preserves the existing organizational pattern where all shell-specific code lives in subdirectories. This cleanly separates SSH transport logic from cache management while reducing code duplication by ~25%. All existing SSH integration behavior remains identical.
…o cache management - Add +list-ssh-cache and +clear-ssh-cache CLI actions - Remove ghostty() wrapper functions from all shell integrations - Improve variable naming in shell scripts for readability Addresses @00-kat's feedback about CLI discoverability and naming consistency. The new CLI actions follow established Ghostty patterns and are discoverable via `ghostty --help`, while maintaining clean separation of concerns between shell logic and cache management.
Updates Config.zig documentation to reflect that SSH cache management is now handled by proper CLI actions (+list-ssh-cache and +clear-ssh-cache) rather than shell wrapper commands. Fixes documentation missed in e8c8a51.
- Clarify that +list-ssh-cache shows shell integration cached hosts - Add note about +clear-ssh-cache command and when to use it Addresses mitchellh's feedback on action descriptions.
6135bff
to
0ccb7cf
Compare
Clarifies this clears hosts cached by SSH shell integration, completing mitchellh's feedback on both action descriptions.
Aside: should the Bash dependency be documented for now? |
forgot to disable autoformat for this buffer (again)
Makes sense if we're going to move forward with this as an interim solution. Added a dependency note in 1873add |
It might be useful to mention it in Also, another aside: the website's docs would also need to be updated after this is merged. (I'm just mentioning this now so that it isn't forgotten, not saying it should be done now.) |
…lication in ssh_cache - Fix fallback path from full path to "src" since full path is built later - Extract duplicate code from listCachedHosts and clearCache into runCacheCommand helper - Addresses feedback from @00-kat
infocmp is required locally to extract terminfo, tic is required on remote hosts to install it
…n shell integration GHOSTTY_VERSION was mistakenly referenced but is never set. Use TERM_PROGRAM_VERSION which is actually provided by Exec.zig from build_config.version_string.
Addresses #4156 and #5892, specifically by implementing @mitchellh's request for "opt-in shell integration".
Problem
Ghostty's custom
xterm-ghostty
TERM value breaks terminal functionality when SSHing to remote systems that lack the corresponding terminfo entry. This affects enterprise environments, legacy servers, and ephemeral instances.Solution
Adds two independent SSH integration flags within the existing
shell-integration-features
configuration:ssh-env
: TERM compatibility fix (xterm-ghostty → xterm-256color) + environment variable propagation (COLORTERM, TERM_PROGRAM, TERM_PROGRAM_VERSION)ssh-terminfo
: Automatic terminfo installation on remote hosts with caching and utility commandsFlags work independently and harmoniously when combined, allowing users granular control over SSH integration behavior.
Implementation
Adds SSH wrapper functions across bash, zsh, fish, and elvish that handle TERM compatibility, environment propagation, and terminfo installation. Follows the same pattern as existing shell integration features - client-side only with graceful fallback behavior.
The flag-based approach allows users to choose exactly the features they need:
ssh-env
ssh-terminfo
ssh-env,ssh-terminfo
Evolution Note
Based on maintainer feedback, this evolved from a progressive enhancement approach (
ssh-integration = basic | full
) to independent flags withinshell-integration-features
. See discussion below for the complete architectural evolution and rationale.