ed

[hare] The standard editor
Log | Files | Refs | README | LICENSE

commit 97ceeeaf3ef19e9c6481438f0eece7fbf645fee8
parent c6e760822079b72a02ac4dc23d9b88cae4725f53
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun, 19 Feb 2023 19:27:27 +0000

add cmd_shellescape() draft

Diffstat:
Mcommand.ha | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/command.ha b/command.ha @@ -3,6 +3,7 @@ use fmt; use fs; use io; use os; +use os::exec; use regex; use strings; @@ -534,7 +535,22 @@ fn cmd_linenumber(s: *session, cmd: *command) (void | error) = { fmt::println(n)!; }; -fn cmd_shellescape(s: *session, cmd: *command) (void | error) = void; +fn cmd_shellescape(s: *session, cmd: *command) (void | error) = { + let shcmd = exec::cmd("sh", "-c", cmd.arg)!; + let pipe = exec::pipe(); + exec::addfile(&shcmd, os::stdout_file, pipe.1); + let proc = exec::start(&shcmd)!; + io::close(pipe.1)!; + + let data = io::drain(pipe.0)!; + io::close(pipe.0)!; + exec::wait(&proc)!; + + fmt::print(strings::fromutf8(data)!)!; + if (!s.suppressmode) { + fmt::println("!")!; + }; +}; fn cmd_null(s: *session, cmd: *command) (void | error) = { const n = get_linenum(