summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-07 16:36:05 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-08 01:50:54 +0200
commit7aaf4f2423e2bcabce508e91255de673db50b728 (patch)
treecfdfc247185d7a97fce6f96110fb964f00b766fe /main.c
parent60b250c267e9ce69f428fd2f0f56a4b1a54f2004 (diff)
downloadksh-master.tar.gz
Add [-w write-file] optionHEADmaster
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.
Diffstat (limited to 'main.c')
-rw-r--r--main.c12
1 files changed, 12 insertions, 0 deletions
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");