commit
230014a536
|
|
@ -133,13 +133,23 @@ pub fn run(alloc: Allocator) !u8 {
|
||||||
// so this is not a big deal.
|
// so this is not a big deal.
|
||||||
comptime assert(builtin.link_libc);
|
comptime assert(builtin.link_libc);
|
||||||
|
|
||||||
const editorZ = try alloc.dupeZ(u8, editor);
|
var buf: std.ArrayListUnmanaged(u8) = .empty;
|
||||||
defer alloc.free(editorZ);
|
errdefer buf.deinit(alloc);
|
||||||
const pathZ = try alloc.dupeZ(u8, path);
|
|
||||||
defer alloc.free(pathZ);
|
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(
|
const err = std.posix.execvpeZ(
|
||||||
editorZ,
|
"sh",
|
||||||
&.{ editorZ, pathZ },
|
&.{ "sh", "-c", command },
|
||||||
std.c.environ,
|
std.c.environ,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ pub fn ShellEscapeWriter(comptime T: type) type {
|
||||||
|
|
||||||
const Writer = std.io.Writer(*ShellEscapeWriter(T), error{Error}, write);
|
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 {
|
pub fn writer(self: *ShellEscapeWriter(T)) Writer {
|
||||||
return .{ .context = self };
|
return .{ .context = self };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue