summaryrefslogtreecommitdiff
path: root/src/termio/shell_integration.zig
AgeCommit message (Collapse)Author
2025-10-03Zig 0.15: zig build test Mitchell Hashimoto
2025-09-30feat: add GHOSTTY_BIN_DIR to path via shell integrationMatthew Hrehirchuk
2025-08-19zsh: add tests for setupZshJon Parise
2025-07-10bash: preserve an existing ENV valueJon Parise
Our bash shell integration code uses ENV (in POSIX mode) to bootstrap our shell integration script. This had the side effect of overwriting an existing ENV value. This change preserves ENV by storing it temporarily in GHOSTTY_BASH_ENV. Note that this doesn't enable --posix mode support for automatic shell integration. (--posix does work; we just skip shell integration when that flag is specified.) We can reconsider implementing full --posix support separately.
2025-07-09cli: rewrite ssh-cache diskcache and test IOMitchell Hashimoto
2025-06-25test: update shell integration tests for SSH flagsJason Rayne
Add ssh-env and ssh-terminfo fields to existing setupFeatures tests.
2025-06-25change: migrate SSH integration from standalone option to ↵Jason Rayne
shell-integration-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.
2025-06-25feat: add SSH integration wrapper for shell integrationJason Rayne
- Implements opt-in SSH wrapper following sudo pattern - Supports term_only, basic, and full integration levels - Fixes xterm-ghostty TERM compatibility on remote systems - Propagates shell integration environment variables - Allows for automatic installation of terminfo if desired - Addresses GitHub discussions #5892 and #4156
2025-05-05bash: explicitly request a login shellJon Parise
Prior to #7044, on macOS, our shell integrated command line would be executed under `exec -l`, which caused bash to be started as a login shell. Now that we're using direct command execution, add `--login` to our bash command's arguments on macOS to get that same behavior.
2025-04-10config: allow commands to specify whether they shell expand or notMitchell Hashimoto
This introduces a syntax for `command` and `initial-command` that allows the user to specify whether it should be run via `/bin/sh -c` or not. The syntax is a prefix `direct:` or `shell:` prior to the command, with no prefix implying a default behavior as documented. Previously, we unconditionally ran commands via `/bin/sh -c`, primarily to avoid having to do any shell expansion ourselves. We also leaned on it as a crutch for PATH-expansion but this is an easy problem compared to shell expansion. For the principle of least surprise, this worked well for configurations specified via the config file, and is still the default. However, these configurations are also set via the `-e` special flag to the CLI, and it is very much not the principle of least surprise to have the command run via `/bin/sh -c` in that scenario since a shell has already expanded all the arguments and given them to us in a nice separated format. But we had no way to toggle this behavior. This commit introduces the ability to do this, and changes the defaults so that `-e` doesn't shell expand. Further, we also do PATH lookups ourselves for the non-shell expanded case because thats easy (using execvpe style extensions but implemented as part of the Zig stdlib). We don't do path expansion (e.g. `~/`) because thats a shell expansion. So to be clear, there are no two polar opposite behavioes here with clear semantics: 1. Direct commands are passed to `execvpe` directly, space separated. This will not handle quoted strings, environment variables, path expansion (e.g. `~/`), command expansion (e.g. `$()`), etc. 2. Shell commands are passed to `/bin/sh -c` and will be shell expanded as per the shell's rules. This will handle everything that `sh` supports. In doing this work, I also stumbled upon a variety of smaller improvements that could be made: - A number of allocations have been removed from the startup path that only existed to add a null terminator to various strings. We now have null terminators from the beginning since we are almost always on a system that's going to need it anyways. - For bash shell integration, we no longer wrap the new bash command in a shell since we've formed a full parsed command line. - The process of creating the command to execute by termio is now unit tested, so we can test the various complex cases particularly on macOS of wrapping commands in the login command. - `xdg-terminal-exec` on Linux uses the `direct:` method by default since it is also assumed to be executed via a shell environment.
2025-03-22shell-integration: minor documentation updatesJon Parise
2025-03-22shell-integration: comptime buffer capacityJon Parise
2025-03-22shell-integration: switch to $GHOSTTY_SHELL_FEATURESJon Parise
This change consolidates all three opt-out shell integration environment variables into a single opt-in $GHOSTTY_SHELL_FEATURES variable. Its value is a comma-delimited list of the enabled shell feature names (e.g. "cursor,title"). $GHOSTTY_SHELL_FEATURES is set at runtime and automatically added to the shell environment. Its value is based on the shell-integration-features configuration option. $GHOSTTY_SHELL_FEATURES is only set when at least one shell feature is enabled. It won't be set when 'shell-integration-features = false'. $GHOSTTY_SHELL_FEATURES lists only the enabled shell feature names. We could have alternatively gone in the opposite direction and listed the disabled features, letting the scripts assume each feature is on by default like we did before, but I think this explicit approach is a little safer and easier to reason about / debug. It also doesn't support the "no-" negation prefix used by the config system (e.g. "cursor,no-title"). This simplifies the implementation requirements of our (multiple) shell integration scripts, and because $GHOSTTY_SHELL_FEATURES is derived from shell-integration-features, the user-facing configuration interface retains that expressiveness. $GHOSTTY_SHELL_FEATURES is intended to primarily be an internal concern: an interface between the runtime and our shell integration scripts. It could be used by people with particular use cases who want to manually source those scripts, but that isn't the intended audience. ... and because the previous $GHOSTTY_SHELL_INTEGRATION_NO_* variables were also meant to be an internal concern, this change does not include backwards compatibility support for those names. One last advantage of a using a single $GHOSTTY_SHELL_FEATURES variable is that it can be easily forwarded to e.g. ssh sessions or other shell environments.
2025-03-12Lots of 0.14 changesMitchell Hashimoto
2025-01-23bash: handle additional command argumentsJon Parise
A '-' or '--' argument signals the end of bash's own options. All remaining arguments are treated as filenames and arguments. We shouldn't perform any additional argument processing once we see this signal. We could also assume a non-interactive shell session in this case unless the '-i' (interactive) shell option has been explicitly specified, but let's wait on that until we know that doing so would solve a real user problem (and avoid any false negatives).
2025-01-18Ensure `setup_features` runs even when shell detection failsBryan Lee
2025-01-18Add tests for setup shell integration featuresBryan Lee
2025-01-18Fix `shell-integration-features` being ignored when `shell-integration` is ↵Bryan Lee
`none`
2025-01-07bash: drop automatic shell integration with --posixJon Parise
'--posix' starts bash in POSIX mode (like /bin/sh). This is rarely used for interactive shells, and removing automatic shell integration support for this option allows us to simply/remove some exceptional code paths. Users are still able to manually source the shell integration script. Also fix an issue where we would still inject GHOSTTY_BASH_RCFILE if we aborted the automatic shell integration path _after_ seeing an --rcfile or --init-file argument.
2024-12-16os: add prependEnv(), like appendEnv()Jon Parise
We can use this function in setupXdgDataDirs() to simplify the XDG_DATA_DIRS environment variable code in a more standardized way.
2024-12-14bash: re-enable automatic bash shell detectionJon Parise
Bash shell detection was originally disabled in #1823 due to problems with /bin/bash on macOS. Apple distributes their own patched version of Bash 3.2 on macOS that disables the POSIX-style $ENV-based startup path: https://github.com/apple-oss-distributions/bash/blob/e5397a7e74633a4e84194a6c6b609e04077da6f8/bash-3.2/shell.c#L1112-L1114 This means we're unable to perform our automatic shell integration sequence in this specific environment. Standard Bash 3.2 works fine. Knowing this, we can re-enable bash shell detection by default unless we're running "/bin/bash" on Darwin. We can safely assume that's the unsupported Bash executable because /bin is non-writable on modern macOS installations due to System Integrity Protection. macOS users can either manually source our shell integration script (which otherwise works fine with Apple's Bash) or install a standard version of Bash from Homebrew or elsewhere.
2024-11-23termio: copy input command to avoid memory corruptionMitchell Hashimoto
Fixes #2779
2024-11-17termio: tweaks to xdg data dir handling (no logic changes)Mitchell Hashimoto
2024-11-17Append the default value of XDG_DATA_DIRS when setting up shell integrationnotcancername
2024-08-05chore: clean up typosŁukasz Niemier
2024-07-22Fix multiple deprecated names for zig lib/stdmultifred
2024-06-03shell-integration: bash must be explicitly enabledJon Parise
For now, bash integration must be explicitly enabled (by setting `shell-integration = bash`). Our automatic shell integration requires bash version 4 or later, and systems like macOS continue to ship bash version 3 by default. This approach avoids the cost of performing a runtime version check.
2024-05-27rename env varMitchell Hashimoto
2024-05-27refactor(shell-integration): refactor to make cases alphabeticalilk
also refactors elvish file to evade unobvious returns and tries to fix some build errors
2024-05-27feat(shell-integration): add automatic integration for Elvishilk
Fish automatic integration taken as an example. Just like fish, Elvish checks `XDG_DATA_DIRS` for its modules. Thus, Fish integration in zig is reused, and integration in Elvish now removes `GHOSTTY_FISH_XDG_DIR` environment variable on launch.
2024-05-14shell-integration: handle 'bash -c command'Jon Parise
When the -c option is present, then commands are read from the first non-option argument command string. Our simple implementation assumes that if we see at least the '-c' option, a command string was given, and the shell is always considered to be non-interactive - even if the '-i' (interactive) option is also given.
2024-05-08shell-integration: expand bash HISTFILE valueJon Parise
bash reads HISTFILE at startup to locate its history file, but this is apparently too early for it to be able to expand home-relative paths. We now manually expand the full path and add that to the environment.
2024-05-07termio: shell integration uses arenaMitchell Hashimoto
2024-05-05shell-integration: revise ShellIntegration.command commentJon Parise
2024-05-05shell-integration: automatic bash integrationJon Parise
This change adds automatic bash shell detection and integration. Unlike our other shell integrations, bash doesn't provide a built-in mechanism for injecting our ghostty.bash script into the new shell environment. Instead, we start bash in POSIX mode and use the ENV environment variable to load our integration script, and the rest of the bash startup sequence becomes the responsibility of our script to emulate (along with disabling POSIX mode).
2024-04-21termio: pass full command to shell integrationJon Parise
This will allow the shell integration code to inspect the full command string rather than just the first component (shell binary).
2024-04-20termio: fix "forced" shell integrationJon Parise
When a shell is forced, we would supply its /-prefixed executable name to mimic a path location. The rest of the integration detection logic assumes just a base executable name. Fix the forced names accordingly. Also add a unit test for this "force shell" behavior.
2024-04-03shell-integration: implement no-title optionMarius Svechla
This adds a new option to the shell integration feature set, `no-title`. If this option is set, the shell integration will not automatically update the window title.
2024-01-13add sudo wrapper as optional shell integration featureAtanas Pepechkov
2024-01-05termio: support XDG data dirs greater than 4k for fish shell integrationMitchell Hashimoto
Fixes #1228
2023-11-07config: switch shell-integration-featuresMitchell Hashimoto
2023-07-06allow configuring shell integration injectionMitchell Hashimoto
2023-07-06zsh integrationMitchell Hashimoto
2023-07-06fish shell integrationMitchell Hashimoto
2023-07-06termio: fish shell integration injectionMitchell Hashimoto