don't look up default shell from SHELL env if shell is set

This commit is contained in:
Mitchell Hashimoto
2023-03-19 12:13:41 -07:00
parent 638e05454f
commit f28b677417

View File

@ -557,34 +557,42 @@ pub const Config = struct {
if (self.command == null or wd_home) command: { if (self.command == null or wd_home) command: {
const alloc = self._arena.?.allocator(); const alloc = self._arena.?.allocator();
// We don't do this in flatpak because SHELL in Flatpak is // First look up the command using the SHELL env var if needed.
// always set to /bin/sh // We don't do this in flatpak because SHELL in Flatpak is always
// set to /bin/sh.
if (self.command) |cmd|
log.info("shell src=config value={s}", .{cmd})
else {
if (!internal_os.isFlatpak()) { if (!internal_os.isFlatpak()) {
// First look up the command using the SHELL env var.
if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| { if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| {
log.debug("default shell source=env value={s}", .{value}); log.info("default shell source=env value={s}", .{value});
self.command = value; self.command = value;
// If we don't need the working directory, then we can exit now. // If we don't need the working directory, then we can exit now.
if (!wd_home) break :command; if (!wd_home) break :command;
} else |_| {} } else |_| {}
} }
}
// We need the passwd entry for the remainder // We need the passwd entry for the remainder
const pw = try passwd.get(alloc); const pw = try passwd.get(alloc);
if (self.command == null) { if (self.command == null) {
if (pw.shell) |sh| { if (pw.shell) |sh| {
log.debug("default shell src=passwd value={s}", .{sh}); log.info("default shell src=passwd value={s}", .{sh});
self.command = sh; self.command = sh;
} }
} }
if (wd_home) { if (wd_home) {
if (pw.home) |home| { if (pw.home) |home| {
log.debug("default working directory src=passwd value={s}", .{home}); log.info("default working directory src=passwd value={s}", .{home});
self.@"working-directory" = home; self.@"working-directory" = home;
} }
} }
if (self.command == null) {
log.warn("no default shell found, will default to using sh", .{});
}
} }
} }