Help request: How to set the tab title according to the prompt with Cygwin bash / OSC 2 documentation? #23983

Closed
opened 2026-01-31 08:58:07 +00:00 by claunia · 3 comments
Owner

Originally created by @Binarus on GitHub (Jan 22, 2026).

Hello everybody,

I like Windows Terminal very much, and it gets better with every version. I am looking forward to the future development.

However, since ages I have a problem that becomes more pain from day to day, so I have now decided to ask for help. Amongst others, I am using Terminal on Windows together with Cygwin (bash) to perform management tasks on remote servers via SSH. I often have a dozen of Terminal tabs open, each containing a session to a different server.

In this scenario, I would like each Terminal tab title to be the remote server host name, and to change dynamically if I close the respective session with the host and connect to a new host.

The prompt in Cygwin bash is configured so that it contains the host name. For example, if I am connected to host cerberus as user user, the prompt contains user@cerberus.

I think that I have understood how the interaction between Terminal and the shell works. The problem is that I can't find any documentation for this specific use case. The only hint about it is in Terminal's UI itself. The help text for the option Suppress title changes in the profile settings reads: Ignore application requests to change the title (OSC 2).

I am aware that this option must be turned off, but that's not the subject of the question. The key point is the OSC 2. I guess I would be able to alter my prompt to send OSC 2 to Terminal. But obviously, that would lead to nowhere as long as the text (tab title) itself is missing. In other words, I don't know the format of a complete OSC 2 command, and I can't find any information about it.

In contrast, (some of?) the OSC 133 commands are documented:
https://devblogs.microsoft.com/commandline/shell-integration-in-the-windows-terminal/#how-does-this-work

But I was not able to spot something similar for the OSC 2 commands.

Can somebody please help me out there?

Originally created by @Binarus on GitHub (Jan 22, 2026). Hello everybody, I like Windows Terminal very much, and it gets better with every version. I am looking forward to the future development. However, since ages I have a problem that becomes more pain from day to day, so I have now decided to ask for help. Amongst others, I am using Terminal on Windows together with Cygwin (bash) to perform management tasks on remote servers via SSH. I often have a dozen of Terminal tabs open, each containing a session to a different server. In this scenario, I would like each Terminal tab title to be the remote server host name, and to change dynamically if I close the respective session with the host and connect to a new host. The prompt in Cygwin bash is configured so that it contains the host name. For example, if I am connected to host `cerberus` as user `user`, the prompt contains `user@cerberus`. I think that I have understood how the interaction between Terminal and the shell works. The problem is that I can't find any documentation for this specific use case. The only hint about it is in Terminal's UI itself. The help text for the option `Suppress title changes` in the profile settings reads: `Ignore application requests to change the title (OSC 2).` I am aware that this option must be turned off, but that's not the subject of the question. The key point is the `OSC 2`. I guess I would be able to alter my prompt to send `OSC 2` to Terminal. But obviously, that would lead to nowhere as long as the text (tab title) itself is missing. In other words, I don't know the format of a complete `OSC 2` command, and I can't find any information about it. In contrast, (some of?) the `OSC 133` commands are documented: https://devblogs.microsoft.com/commandline/shell-integration-in-the-windows-terminal/#how-does-this-work But I was not able to spot something similar for the `OSC 2` commands. Can somebody please help me out there?
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 08:58:07 +00:00
Author
Owner

@MichaelJOHare commented on GitHub (Jan 23, 2026):

Not sure if I understand the question 100% but I changed tab titles when connecting with ssh by making an ssh wrapper function that just did:

printf '\033]2;%s\007' "$user@$host"

Just grab $1 and split on "@" to get the individual user and host. Is that what you're asking?

@MichaelJOHare commented on GitHub (Jan 23, 2026): Not sure if I understand the question 100% but I changed tab titles when connecting with ssh by making an ssh wrapper function that just did: `printf '\033]2;%s\007' "$user@$host"` Just grab $1 and split on "@" to get the individual user and host. Is that what you're asking?
Author
Owner

@Binarus commented on GitHub (Jan 23, 2026):

@MichaelJOHare Thank you very much! Yes, that's exactly what I was asking.

I believe that quite a few guys out there have the same problem, so I'll try to describe the problem in other words. For example, when looking into the link from my first post, we can tell Terminal the working directory by OSC 9 ; 9 ; <CWD> ST, or we can tell it about a finished command by OSC 133 ; D ; <ExitCode> ST, and so on.

From that, we see that the OSC strings (commonly called control sequences or escape sequences) have a special format. Unfortunately, the format for OSC 2 (which is used to set the Terminal tab title) doesn't seem to be documented, and of course I thought that it was similar to the other commands mentioned above.

Therefore, I am very grateful for your code. Obviously, the format is simpler than I suspected. For the record, in terms of the documentation I have linked, the command to set the tab title seems to be OSC 2 ; <TAB_TITLE> ST.

Now that I know the correct format, I have changed the prompt definition on a few of the remote systems accordingly, and that works, too. This means that we now have even two methods to solve the problem.

@Binarus commented on GitHub (Jan 23, 2026): @MichaelJOHare Thank you very much! Yes, that's exactly what I was asking. I believe that quite a few guys out there have the same problem, so I'll try to describe the problem in other words. For example, when looking into the link from my first post, we can tell Terminal the working directory by `OSC 9 ; 9 ; <CWD> ST`, or we can tell it about a finished command by `OSC 133 ; D ; <ExitCode> ST`, and so on. From that, we see that the `OSC` strings (commonly called control sequences or escape sequences) have a special format. Unfortunately, the format for `OSC 2` (which is used to set the Terminal tab title) doesn't seem to be documented, and of course I thought that it was similar to the other commands mentioned above. Therefore, I am very grateful for your code. Obviously, the format is simpler than I suspected. For the record, in terms of the documentation I have linked, the command to set the tab title seems to be `OSC 2 ; <TAB_TITLE> ST`. Now that I know the correct format, I have changed the prompt definition on a few of the remote systems accordingly, and that works, too. This means that we now have even two methods to solve the problem.
Author
Owner

@MichaelJOHare commented on GitHub (Jan 23, 2026):

@Binarus Ah, I see what you mean now about the initial confusion over the specific format. I'm glad to hear that answered your question though!

@MichaelJOHare commented on GitHub (Jan 23, 2026): @Binarus Ah, I see what you mean now about the initial confusion over the specific format. I'm glad to hear that answered your question though!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#23983