Set Tab Title to your current working directory instead of the current job name in zsh iterms

2

I'm running iTerms on my Mac OS X with zsh. With my workflow I have to switch between tab a lot and sometime I have to spend too much time just to find which tab is the one I'm looking for because all of them having the same name.

enter image description here

As you can see from the screenshot above. Now that would be very useful for me to at least display the Tab Title to the current working directory instead of the Job name in iTerms for zsh

I have looked at the preferences and there is no option for that. It will only display the CWD when the job is not running but once it is running then the job name will be display instead.

Ali

Posted 2013-08-01T17:31:30.110

Reputation: 1 151

possible duplicate of Change iTerm2 window and tab titles in zsh

– mpy – 2013-08-02T07:45:56.547

@mpy well that is not really answered my question because when the process is running the name is changed again. – Ali – 2013-08-07T03:35:41.303

1You are right, it does not answer exactly your question. But I was thinking of it as a duplicate, because in the linked answers you get (a.) the escape sequences how to set tab and window title and (b.) the hint about precmd. But I must admit, that in your case it could also be the function preexec which changes your title -- I retracted my close vote. – mpy – 2013-08-07T10:53:38.160

Thanks. I will do some research on how to do that because it is very annoying not to know which tab is which. – Ali – 2013-08-07T12:30:40.250

Answers

3

Check the hook functions precmd and preexec with which precmd and which preexec, resp.:

precmd Executed before each prompt. (...)

preexec Executed just after a command has been read and is about to be executed. (...) The actual command that will be executed (including expanded aliases) is passed in two different forms: the second argument is a single-line, size-limited version of the command (with things like function bodies elided); the third argument contains the full text that is being executed.

Probably in preexec there is some code which changes the tab title to $2 or $3.

As a first test you can disable both hook functions completely (precmd() {}, preexec() {}), set the title manually (echo -ne "\e]1;TEST\a") and check if it remains if you execute a command.

Then try to find the source of the original setting, either in you personal RC files (~/.zshrc) or the system wide ones (/etc/zsh*).

If sucessful, you can think about a sensible tab title and put the echo command to precmd like suggested by @Tiago.

mpy

Posted 2013-08-01T17:31:30.110

Reputation: 20 866

1

Edit your zsh configuration files to set the title in the precmd() function to e.g. $PWD.

echo -ne "\e]1;$PWD\a"

stderr

Posted 2013-08-01T17:31:30.110

Reputation: 9 300

I'm not sure if I understand that right, but getting the present working directory overwrite the current job is that the way you do it? – Ali – 2013-08-01T18:27:32.313