2

I'm wondering whether others have experienced this issue (below in bold) and/or found a workaround: in macOS (any version that I've tried which provides Terminal access, so I'm assuming OS X on up; on any hardware), a Terminal or iTerm2 window gets named with the active top-level process until it ends or you quit it. Expected behavior for all systems with Terminal access, right?

When using SSH in Terminal or iTerm2 on macOS, the name of the remote machine populates the top of the window. Also expected. The unexpected comes when you exit out of the SSH session, and the name of the remote machine you had SSH'ed into persists in the window banner; there is no more visibility in the window banner of your current top-level running process, until and unless you close the window (losing some access to command history), and open a new window.

I've never seen this process-stuck behavior on the banner of a Terminal window in any other OS; various forms of Terminal on Linux distros exit out of SSH and get back to showing the top-level running process fine, as does CMD or PowerShell in Windows. What's going on with macOS, and why has this behavior never been addressed, at least as for as my limited DuckDuckGo-fu (or !G-fu) can find?

Has anyone else experienced this?

Insight welcome. Thanks!

Marc Wilson
  • 121
  • 4
juanejot
  • 21
  • 2
  • I also find this problem but it never bothered me... Any progress? – Gordon Bai Feb 27 '21 at 13:35
  • I provided an answer below, but a comment... if you are losing command history just because you closed a window with a running shell, fix your shell configuration. With `ksh` you can't not save it (the deliberate act is deleting it), with `bash` that's what `shopt -o histappend` is for. For `zsh` it is such a maze of twisty little variables I have no idea other than it depends on $RCS. – Marc Wilson Mar 26 '21 at 21:14

1 Answers1

1

There's no "process stick" going on.

Let's address several things here.

First, please note... "shell" != "terminal", and if you think it does, you are mistaken.

You state:

When using SSH in Terminal or iTerm2 on macOS, the name of the remote machine populates the top of the window.

Yes, if the remote shell sets the terminal window title. Usually in a prompt. Sometimes in a shell initialization rc file. With ksh you even see people overloading things like cd(1), which is a little silly.

Then you state:

The unexpected comes when you exit out of the SSH session, and the name of the remote machine you had SSH'ed into persists in the window banner

Because the remote shell set the title of the terminal window and the local shell does not reset it when it regains control.

And finally:

What's going on with macOS, and why has this behavior never been addressed, at least as for as my limited DuckDuckGo-fu (or !G-fu) can find?

If you want whatever shell you are using to do something, configure it to do that thing. Otherwise, it will not do that thing. There's nothing to address... it's not broken.

macOS default init for ksh doesn't set any prompt at all, for zsh all that's set up is user name, machine name, and current $PWD, and bash is the same. None of them set the terminal window title.

Seems rather obvious what's going on.

So. If you want your terminal window titles to reflect this information:

  • the local shell needs to set the window title
  • the remote shell(s) need to set the window title

It seems you have the second one handled, so fix the first one. Most people do it by adding control codes to the shell prompt so that it changes the window as reliably as possible.

You may find this reference helpful.

Marc Wilson
  • 121
  • 4