Index: io.c =================================================================== RCS file: /cvs/src/bin/ksh/io.c,v diff -u -p -u -p -r1.38 io.c --- io.c 24 Jul 2019 14:33:16 -0000 1.38 +++ io.c 5 Jan 2024 20:02:04 -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: lex.c =================================================================== RCS file: /cvs/src/bin/ksh/lex.c,v diff -u -p -u -p -r1.79 lex.c --- lex.c 8 Feb 2023 17:22:10 -0000 1.79 +++ lex.c 5 Jan 2024 20:02:05 -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: main.c =================================================================== RCS file: /cvs/src/bin/ksh/main.c,v diff -u -p -u -p -r1.100 main.c --- main.c 23 Jul 2023 23:42:03 -0000 1.100 +++ main.c 5 Jan 2024 20:02:05 -0000 @@ -623,6 +623,12 @@ shell(Source *volatile s, volatile int t mcheck(); #endif /* SMALL */ 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); Index: sh.h =================================================================== RCS file: /cvs/src/bin/ksh/sh.h,v diff -u -p -u -p -r1.77 sh.h --- sh.h 21 Jun 2023 22:22:08 -0000 1.77 +++ sh.h 5 Jan 2024 20:02:05 -0000 @@ -474,6 +474,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