简体   繁体   中英

Terminal/iTerm2 window name on macOS: how to un-stick SSH to show next process?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM