The DEBUG
trap, supported by both zsh since the start (1990) and bash since 2.0 (1996) is actually from ksh88¹ (1988, it wasn't there in ksh86 AFAICT).
pdksh was a public domain clone of ksh88, like bash/zsh written at a time when the source of ksh wasn't available as opensource yet². It's no longer maintained though there are shells based on it that survive such as the sh
/ksh
of OpenBSD and that of MirBSD, aka mksh
which is still portably and readily available on other systems (it's also the Android shell). There's no really good reason to still be using pdksh in this day and age.
As noted in its man page, pdksh did not support ksh88's debug trap, and as of writing mksh doesn't either.
In ksh, something approaching tcsh/zsh's precmd
hook or bash's $PROMPT_COMMAND
to run something before the prompt is issued could be done by using command substitution in $PS1
.
exec 3>&1 PS1='$(handler>&3)$ '
Would run handler in a subshell (though see ${|handler>&3}
or ${ handler>&3}
in recent versions of mksh to avoid the subshell.
That may help for your __update_title
to reset the title after the user is back to the prompt, but not really for setting the title to current running command(s). For that, you'd probably be better of running a background task that regularly inspects the output of ps -o stat= -o args=
to see which processes run in foreground and what command they are executing.
¹ Though it was triggered after each command, and AFAIK, the command being evaluated was not available in the trap code. zsh also used to run it after, but a DEBUG_BEFORE_CMD
option was added to change that behaviour in 4.3.3 (2007) and made the default in 4.3.6 (2008) along with $ZSH_DEBUG_CMD
containing a representation of the command being executed.
² and only ksh93 (a rewrite from scratch) was made available as opensource circa 2000, ksh88 code is still not opensource though it's not hard to find versions thereof at archive.org or elsewhere.