config: do not load command from SHELL when launched from desktop

Fixes #139

From the issue:

Looking into this now, I think I figured out the broken logic. When launching
from open, the parent process of Ghostty is launchd which appears to set your
SHELL env var to your configured shell when logging in. That's why a restart
fixes it. However, I believe directory services (the macOS equivalent to
/etc/passwd) is updated in real time.

Ghostty does read directory services but at a lower priority than SHELL.
This logic makes sense for CLI-launched terminals but not desktop-launched.
From a CLI you want the terminal you're launching to probably inherit the shell
from the CLI you launched it from. (Note that using open explicitly forces a
launchd-style launch so it quacks as if it was double-clicked on the desktop).

In conclusion, I believe the correct logic is to invert the priority on SHELL
vs directory services when Ghostty detects it was launched from launchd. We
already have this detection logic in Ghostty because we use it for a number of
other things as well, so this should be easy to fix. I'll work on it later
today.
This commit is contained in:
Mitchell Hashimoto
2024-01-06 12:31:01 -08:00
parent 8a816dc5ef
commit d65fbba39e

View File

@ -1674,8 +1674,15 @@ pub fn finalize(self: *Config) !void {
// set to /bin/sh. // set to /bin/sh.
if (self.command) |cmd| if (self.command) |cmd|
log.info("shell src=config value={s}", .{cmd}) log.info("shell src=config value={s}", .{cmd})
else { else shell_env: {
if (!internal_os.isFlatpak()) { // Flatpak always gets its shell from outside the sandbox
if (internal_os.isFlatpak()) break :shell_env;
// If we were launched from the desktop, our SHELL env var
// will represent our SHELL at login time. We want to use the
// latest shell from /etc/passwd or directory services.
if (internal_os.launchedFromDesktop()) break :shell_env;
if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| { if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| {
log.info("default shell source=env value={s}", .{value}); log.info("default shell source=env value={s}", .{value});
self.command = value; self.command = value;
@ -1684,7 +1691,6 @@ pub fn finalize(self: *Config) !void {
if (!wd_home) break :command; if (!wd_home) break :command;
} else |_| {} } else |_| {}
} }
}
switch (builtin.os.tag) { switch (builtin.os.tag) {
.windows => { .windows => {