1

I'm a frequent terminal user. I started Terminal when I got this machine, and it's been running ever since. I always have 8-10 tabs open, and I'd like to get more organized - meaning that I'd like to have permanent tab titles. Permanent tab titles will help me keep all related Terminal activities located under the same tab; e.g. a tab where I stay logged in to an SSH connection to my NAS; another tab for doing git activity on a local repo, etc, etc.

That has been my quest for a few weeks, but I'm no closer now than I was when I started! I've read several Q&A here (1, 2, 3) & on other SE sites. I've searched, and read - but mostly the things I read either flatly do not work at all, or they work only temporarily. I'm sure I must be missing something fundamental, but I've been unable to work out what that is.

For example, this frequently upvoted answer advises that I should be able to set the terminal tab name from the command line as follows:

% echo -en "\033]1; New Name \007"
# -- OR --
% printf '\e]1;%s\a' 'New Name'

I've tried both of these - multiple times - and it does nothing! I'll also say there are several things in this answer that I do not follow at all.

I've followed this Apple User Guide for Terminal. It advises starting the "Inspector" to change the Title and/or Tab. It actually does change the Title and Tab - but they revert to "something else" as soon as anything is typed at the command line in the tab. I fail to see what possible use that is to anyone?

If it makes any difference, I am using the pure zsh prompt.

What am I missing? Is there some way by which I can set a Tab Title that remains constant over repeated usage, re-starts, etc?

0

2 Answers 2

3

You use Pure to generate a pretty prompt. Pure does set titles, it has a function prompt_pure_set_title() for that, and calls it in prompt_pure_preexec() and prompt_pure_precmd(). That's what is overriding what you're doing from the command line.

$PS1 is the variable that ultimately contains the prompt in most shells

Changing the title with echo requires that you send the right escape codes, same as your shell prompt sends. For your example above, the correct sequence would be

$ echo -en "\033]0; New Name \007"

That doesn't stop some other process immediately changing the title to something else.

Or you can set it with Terminal.app itself... that's what the Title field on the Window tab of your current Terminal.app profile is for. But you would then have to override whatever other processes are changing the title.

3
  • Because something else is operating to change it as soon as the prompt returns. This is most likely embedded in your shell prompt, although there are other ways. Look at what might be embedded in your $PS1 variable. Commented Sep 3 at 17:30
  • 1
    Pure does set titles, it has a function prompt_pure_set_title() for it. and calls it in prompt_pure_preexec() and prompt_pure_precmd(). That's what is overriding what you're doing from the command line. $PS1 is the variable that ultimately contains the prompt in most shells. Commented Sep 3 at 20:38
  • Wow - good catch! I actually looked at the code, but completely missed the significance of that as I was focused on 'tab' - not 'title'. Apparently they're intertwined in Terminal? If you'll edit your answer to add the gist of your comment, I'll upvote & accept. And thanks so much! ... Now I've got to find a new zsh prompt that doesn't take over 'tabs & titles'!
    – Seamus
    Commented Sep 3 at 21:47
0

This is only a follow-up to @MarcWilson's excellent answer, and it's intended for those who may be using pure, or other similar prompts:

After reading Marc's answer, I posted issue #685 on pure's GitHub site. I got a reply almost immediately that explained how to turn off the prompt_pure_set_title() function:

Override the function by inserting a no-op version of the function in ~/.zshrc, after the prompt pure line:

# edit ~/.zshrc, after 'prompt pure' line, add:
prompt_pure_set_title() {} 

# save, exit editor and re-source:
% . ~/.zshrc 

# apply the 'tab/title' modification from Marc's answer:
% echo -en "\033]0; New Name \007"

And it works!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .