Index: bin/ksh/io.c =================================================================== RCS file: /cvs/src/bin/ksh/io.c,v retrieving revision 1.38 diff -u -p -u -p -r1.38 io.c --- bin/ksh/io.c 24 Jul 2019 14:33:16 -0000 1.38 +++ bin/ksh/io.c 28 Dec 2022 07:41:42 -0000 @@ -149,6 +149,20 @@ shellf(const char *fmt, ...) shf_flush(shl_out); } +/* printf to shl_out (stderr) without flush */ +void +shellnof(const char *fmt, ...) +{ + va_list va; + + if (!initio_done) /* shl_out may not be set up yet... */ + return; + va_start(va, fmt); + shf_vfprintf(shl_out, fmt, va); + va_end(va); +} + + /* printf to shl_stdout (stdout) */ void shprintf(const char *fmt, ...) Index: bin/ksh/lex.c =================================================================== RCS file: /cvs/src/bin/ksh/lex.c,v retrieving revision 1.78 diff -u -p -u -p -r1.78 lex.c --- bin/ksh/lex.c 15 Jan 2018 14:58:05 -0000 1.78 +++ bin/ksh/lex.c 28 Dec 2022 07:41:42 -0000 @@ -1157,6 +1157,19 @@ getsc_line(Source *s) s->line++; histsave(s->line, s->str, 1); } + /* Set xterm title */ + char *d = str_val(global("DISPLAY")); + char str[41]; + memset(str, '\0', 41); + for (int i=0; i<40; i++) { + str[i] = p[i]; + if ( (str[i] > 0x7e) || (str[i] < 0x20)) { + str[i] = '\0'; + break; + } + } + if(d[0]) + shellf("%c]0;$ %s%c", '\033', str, '\007'); } if (interactive) set_prompt(PS2); Index: bin/ksh/main.c =================================================================== RCS file: /cvs/src/bin/ksh/main.c,v retrieving revision 1.98 diff -u -p -u -p -r1.98 main.c --- bin/ksh/main.c 28 Jun 2019 13:34:59 -0000 1.98 +++ bin/ksh/main.c 28 Dec 2022 07:41:43 -0000 @@ -609,9 +609,16 @@ shell(Source *volatile s, volatile int t j_notify(); mcheck(); set_prompt(PS1); + /* Reset xterm title */ + char *d = str_val(global("DISPLAY")); + if(d[0] > 0) { + shellnof("%c]0;$ ksh (%s)%c", + '\033', current_wd, '\007'); + } } t = compile(s); + if (t != NULL && t->type == TEOF) { if (wastty && Flag(FIGNOREEOF) && --attempts > 0) { shellf("Use `exit' to leave ksh\n"); Index: bin/ksh/sh.h =================================================================== RCS file: /cvs/src/bin/ksh/sh.h,v retrieving revision 1.76 diff -u -p -u -p -r1.76 sh.h --- bin/ksh/sh.h 7 Jul 2020 10:33:58 -0000 1.76 +++ bin/ksh/sh.h 28 Dec 2022 07:41:43 -0000 @@ -475,6 +475,8 @@ void internal_warningf(const char *, ... void error_prefix(int); void shellf(const char *, ...) __attribute__((__format__ (printf, 1, 2))); +void shellnof(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); void shprintf(const char *, ...) __attribute__((__format__ (printf, 1, 2))); #ifdef KSH_DEBUG