Iterm2+ZSH+Powerlevel10k prompt -> no user@hostname in tab title.

1,314 views
Skip to first unread message

hunter

unread,
Mar 9, 2021, 6:43:54 AM3/9/21
to iterm2-discuss
Hello George,

I've Iterm2 v3.4.4 with ZSH shell. These shells use the iTerm2 integration script and Powerlevel10k prompt.
In the tab only the Current working directory and job name is shown. (see screenshot).
With a bash shell with iTerm2 integration I see "user@hostname:pwd (job name)" as tab title.
How can I get user@hostname also in the tab title for zsh shells?

Screenshot 2021-03-09 at 12.39.59.png

George Nachman

unread,
Mar 9, 2021, 12:30:45 PM3/9/21
to iterm2-...@googlegroups.com
Try setting these values for Title:



--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/0b65db20-9571-4b10-9666-0ad50ddae27bn%40googlegroups.com.

hunter

unread,
Mar 9, 2021, 1:09:30 PM3/9/21
to iterm2-discuss
I tried that already. 
But then it results into "jobname - user@hostname".
The - is a long -.

But then the PWD is missing. I can enable that also, but the home directory will be always the full path and not ~ for the home path.
And the order is different (job name first instead of after the session name)
But why does it not work with the session name as bash shell does? iTerm2 knows the correct username, hostname, etc from the shell/ssh session.

Secondly when path is longer than title bar space is available, you can't see user@hostname part anymore (and most part of path). I can only see the "long line" by hovering over the tabs. When I have 50 SSH tab sessions open, it is terrible to figure out which tab is which session.

Op dinsdag 9 maart 2021 om 18:30:45 UTC+1 schreef George Nachman:

George Nachman

unread,
Mar 9, 2021, 2:08:56 PM3/9/21
to iterm2-...@googlegroups.com
What bash does is it sets the title as part of the command prompt, and you could do the same in zsh by editing your PS1 to contain something like

PS1=$'%{\033]2;YOUR TITLE GOES HERE\033\\} '

If you use oh-my-zsh you’ll need to disable its title-setting feature with:

DISABLE_AUTO_TITLE="true"

Richard Mitchell

unread,
Mar 9, 2021, 2:12:50 PM3/9/21
to iterm2-discuss
locally I run zsh with P10K.  my tab label is some ending of my current path.  if I ssh to non-zsh host, label gets set to user@host:path

I have 'Title:' set to 'Session Name'.  I used to have routines using escape codes to set window and icon labels (from back with Sun/Solaris).  I've since removed those and only assume something in all the zsh is now doing 'it' for me (where 'it' is not your desired outcome).  I only get path on zsh remote hosts as well (also using P10K)

As iTerm2 remains the same between zsh/non-zsh hosts, I think the issue is elsewhere.

hunter

unread,
Mar 10, 2021, 6:57:42 AM3/10/21
to iterm2-discuss
I understand the "static" title changes. But based on what/where does iTerm2 gets the session name dynamically from. From the iterm2 integration script it looks to me it just put username and hostname into variables and push this through escape codes to iTerm2. But session name does not use this, correct?

Op dinsdag 9 maart 2021 om 20:08:56 UTC+1 schreef George Nachman:

George Nachman

unread,
Mar 10, 2021, 7:27:12 PM3/10/21
to iterm2-...@googlegroups.com
Initially, the session name is set to the profile’s name. Later on it can be changed by a trigger, a control sequence, or by editing the session name in the Edit Session panel.

Internally, the session has a variable called autoNameFormat which is an interpolated string that when evaluated produces the session’s autoName. This is documented here: https://iterm2.com/documentation-variables.html

The way in which variables are combined to produce the session title is complicated because it tries to combine things into an intelligible string. The logic is here:

The intended design is that this will satisfy 95% of people. The other 5% can implement a session title provider that does whatever you want using the Python API. There’s an example here: https://iterm2.com/python-api/examples/georges_title.html and it is discussed in the tutorial here: https://iterm2.com/python-api/tutorial/hooks.html

hunter

unread,
Mar 11, 2021, 9:17:31 AM3/11/21
to iterm2-discuss
Thank you for the links.

I belong to the 5% people ;-) I'm going to use this.

One question. When I do a ssh session to a remote host and exit from this session back to the local host session, then the hostname variable value will be always keeping the remote hostname. How can I "reset" this back to local hostname when a ssh session ends?
This issue happens also with the standard Session Name or the standard Host title setting. Regardless of using zsh or bash shell.

Op donderdag 11 maart 2021 om 01:27:12 UTC+1 schreef George Nachman:

George Nachman

unread,
Mar 24, 2021, 1:37:03 AM3/24/21
to iterm2-...@googlegroups.com
The best way to solve this problem is to install shell integration locally. Otherwise the terminal has no way of knowing what happened.

Reply all
Reply to author
Forward
0 new messages