Download raw body.
ksh: add OSC7 support
On Thu, 6 Nov 2025, ori@eigenstate.org wrote:
> I use OSC7 in order to advertise the working directory to the
> terminal emulator I use. While I can hack this together in ksh
> with some scripts, it feels like it would be a better fit to
> have directly in the shell, though I'm uncertain about that.
>
> It seems a bit odd to have support for this in tmux, but not
> emit it in our own shell.
>
> The patch below adds a '\O' option to PS1. It needs to be
> enabled explicitly, as:
>
> PS1=\O\h\$
You can use the existing command substitution support in PS1 to
achieve the same result and without needing to modify ksh.
E.g. here's an example that updates an xterm title with the $PWD
To make work for OSC7 you'd additionally need to provide a
urlencode function.
_tty=`tty 2>/dev/null`
_tty="${_tty#/dev/}"
_shorthost="${HOSTNAME%%.*}"
_xtitle() {
case "$TERM" in
xterm*) printf "%s" "\033]0;$*\007" ;;
esac
}
_ps1cmd() {
_xtitle "${USER}@${_shorthost}:\\\\W (${_tty})"
printf "\015"
}
PS1="$(_ps1cmd)[\u@\h \W]\\$ "
ksh: add OSC7 support