From 8aafc3fa24c7475a07259eb06cd5d217f510df98 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 5 Aug 2026 19:32:30 -0300 Subject: add a Shell builtin, default fish, with per-family prompt integration --- src/builtins.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/builtins.zig') diff --git a/src/builtins.zig b/src/builtins.zig index aaeab5fa..9fa459f2 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -226,6 +226,27 @@ pub const Theme = struct { } }; +/// The binary a NEW terminal execs: `Shell fish`, `Shell zsh`, +/// `Shell /opt/homebrew/bin/bash`. A bare name is looked up on the shells' +/// side against the handful of directories a shell actually lives in — not +/// $PATH, because the lookup has to finish BEFORE the fork (a PATH search +/// allocates, and nothing between fork and exec may). +/// +/// Takes a NAME, so it has no leader path and none in the topbar, for the same +/// reason Theme has neither. Panes already open keep the shell they are +/// running; this is what the next one starts. +pub const Shell = struct { + pub fn run(c: Ctx) void { + const want = std.mem.trim(u8, c.arg orelse return, " \t\r\n"); + // A name too long for the buffer is not silently truncated into a + // DIFFERENT binary — `/very/long/path/to/fish` clipped is a path that + // either does not exist or, worse, does. + if (want.len == 0 or want.len > c.p.shell_buf.len) return; + @memcpy(c.p.shell_buf[0..want.len], want); + c.p.shell_len = @intCast(want.len); + } +}; + /// ...and the list of what Theme takes, as a buffer you walk. Its rows are /// `Theme ` COMMANDS rather than locations, so n/N execute them instead /// of looking them (output_pane.Traits.executes) and stepping the list wears -- cgit v1.3