From 7aaf4f2423e2bcabce508e91255de673db50b728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 7 Jun 2021 16:36:05 +0200 Subject: Add [-w write-file] option ksh will write lines to write-file containing information about the status of the shell: after prompt: empty line after command entry: "cmd" followed by command after cwd change: "cwd" followed by new cwd fg is handled specially, printing a new "cmd" line with the original command associated with the job. --- main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 41d4d80..dad50d3 100644 --- a/main.c +++ b/main.c @@ -278,6 +278,9 @@ main(int argc, char *argv[]) /* Set this before parsing arguments */ Flag(FPRIVILEGED) = getuid() != ksheuid || getgid() != getegid(); + /* set before parse_args */ + writefd = 0; + /* this to note if monitor is set on command line (see below) */ Flag(FMONITOR) = 127; argi = parse_args(argv, OF_CMDLINE, (int *) 0); @@ -286,6 +289,10 @@ main(int argc, char *argv[]) /* NOTREACHED */ } + /* print initial cwd */ + if (writefd) + dprintf(writefd, "cwd%s\n", current_wd); + if (Flag(FCOMMAND)) { s = pushs(SSTRING, ATEMP); if (!(s->start = s->str = argv[argi++])) @@ -578,7 +585,12 @@ shell(s, toplevel) set_prompt(PS1, s); } + if (interactive && writefd) + dprintf(writefd, "\n"); t = compile(s); + if (interactive && writefd && s->start[0] != '\n') + dprintf(writefd, "cmd%s", s->start); + if (t != NULL && t->type == TEOF) { if (wastty && Flag(FIGNOREEOF) && --attempts > 0) { shellf("Use `exit' to leave ksh\n"); -- cgit v1.2.3