summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeffrey C. Ollie <jeff@ocjtech.us>2025-09-24 15:27:46 -0500
committerJeffrey C. Ollie <jeff@ocjtech.us>2025-09-24 17:47:29 -0500
commitbff758f03b077c0c76aa2e677927b9fb26f9efa4 (patch)
treef8cff975445c7eac921ec7c5c123744738c490df /src
parentfc0a37f9e02ffb1adb24cbbd64ed0c3ecfb46ecd (diff)
cli: use sh to launch editor
Diffstat (limited to 'src')
-rw-r--r--src/cli/edit_config.zig22
-rw-r--r--src/os/shell.zig4
2 files changed, 20 insertions, 6 deletions
diff --git a/src/cli/edit_config.zig b/src/cli/edit_config.zig
index dd09d7e2f..116843037 100644
--- a/src/cli/edit_config.zig
+++ b/src/cli/edit_config.zig
@@ -133,13 +133,23 @@ pub fn run(alloc: Allocator) !u8 {
// so this is not a big deal.
comptime assert(builtin.link_libc);
- const editorZ = try alloc.dupeZ(u8, editor);
- defer alloc.free(editorZ);
- const pathZ = try alloc.dupeZ(u8, path);
- defer alloc.free(pathZ);
+ var buf: std.ArrayListUnmanaged(u8) = .empty;
+ errdefer buf.deinit(alloc);
+
+ const writer = buf.writer(alloc);
+ var shellescape: internal_os.ShellEscapeWriter(std.ArrayListUnmanaged(u8).Writer) = .init(writer);
+ var shellescapewriter = shellescape.writer();
+
+ try writer.writeAll(editor);
+ try writer.writeByte(' ');
+ try shellescapewriter.writeAll(path);
+
+ const command = try buf.toOwnedSliceSentinel(alloc, 0);
+ defer alloc.free(command);
+
const err = std.posix.execvpeZ(
- editorZ,
- &.{ editorZ, pathZ },
+ "sh",
+ &.{ "sh", "-c", command },
std.c.environ,
);
diff --git a/src/os/shell.zig b/src/os/shell.zig
index d4d682d3e..3e57031dd 100644
--- a/src/os/shell.zig
+++ b/src/os/shell.zig
@@ -36,6 +36,10 @@ pub fn ShellEscapeWriter(comptime T: type) type {
const Writer = std.io.Writer(*ShellEscapeWriter(T), error{Error}, write);
+ pub fn init(child_writer: T) ShellEscapeWriter(T) {
+ return .{ .child_writer = child_writer };
+ }
+
pub fn writer(self: *ShellEscapeWriter(T)) Writer {
return .{ .context = self };
}