Whenever I connect to one my remote Ubuntu machines, gnome-terminal reflects the fact that I am on the remote machine in the title, using format much like "$USER"@"$(hostname -s)": "$PWD"
. I very much like this default behavior, as it lets me know what machine I am running commands on.
When I connect to my FreeBSD machine as a user that uses sh as it's default shell, the title for gnome-terminal does not update.
I have put the following in my .shrc file:
PS1='['"$USER"'@\h \w'
case "$USER" in
root)
PS1="${PS1}]# "
;;
*)
PS1="${PS1}]$ "
;;
esac
esc="$(printf '\033')"
bel="$(printf '\007')"
case "$TERM" in
xterm)
#cannot get this part to work
PS1='['"${esc}"'0;'"${USER}"'@\h \w'"$bel"']'"$PS1"
;;
*)
;;
esac
So here's the problem. I have found many useful resources, but none seem to indicate how can I set the title using POSIX-complaint sh. Here is the one I found most useful (I was actually able to set the title on bash and ksh using this as reference):
How to change the title of an xterm: examples for different shells
I think I'm nearly there, but I can't seem to figure out what I need to give sh to set the title bar.
printf
into a variable, and that accepts\033
as an escape character. By the way, this is almost certainly a duplicate. – Thomas Dickey Jun 18 '18 at 20:03