20

I don't know if I should ask it here or on unix.stackexchange.com, I found this question here.

My question is similar, I want to change the title of a terminal, I'm using a Debian based distro, Terminator and ZSH, oh-my-zsh the title was fine with bash, but when I moved to ZSH, it shows /bin/zsh as title.

4
  • @DaniëlW.Crompton really? it is a dupe? if so i'll close it right now, i linked to that question, so i know it is there, but didn't know it's a dupe because I'm using a different OS and emulator
    – Lynob
    Aug 19, 2013 at 22:57
  • Did you try out what was advised in the question you linked to? Aug 19, 2013 at 22:59
  • 2
    @DaniëlW.Crompton yes, echo -ne "\e]1;this is the title\a and echo -ne "\e]1;$PWD\a" dont give errors but don't work, i tried unchecking all unless im missing something
    – Lynob
    Aug 19, 2013 at 23:10
  • 1
    Did you try echo -ne "\e]0;$PWD\a" with a 0 rather than 1? Aug 19, 2013 at 23:13

6 Answers 6

16

You set your window title with the xtem escape sequences, in most implementations the first will work best:

echo -en "\e]0;string\a" #-- Set icon name and window title to string
echo -en "\e]1;string\a" #-- Set icon name to string
echo -en "\e]2;string\a" #-- Set window title to string

EDIT: The above only sets the title once. To set zsh to always display the sting in the title you add the following to your .zprofile in your home directory:

case $TERM in
    xterm*)
        precmd () {print -Pn "\e]0;string\a"}
        ;;
esac
3
  • 2
    i said earlier echo -ne "\e]0;$PWD\a" works but when i exit shell, it stops working... I tried you typed in the answer and i get zsh: command not found: stringa and zsh: command not found: e]1 and so on, all of them
    – Lynob
    Aug 19, 2013 at 23:52
  • 1
    Updated the answer Aug 20, 2013 at 13:26
  • To replace home directory within $PWD with ~ I used precmd () {print -Pn "\e]0;${PWD/$HOME/\~}\a"} (Z shell) Dec 22, 2018 at 8:44
19

The following worked for me to rename each tab in gnome-terminal. I added the following code to my ~/.zshrc file.

precmd () { print -Pn "\e]0;$TITLE\a" }
title() { export TITLE="$*" }

This creates a title function to rename each tab.

Note, if you are using oh-my-zsh you will need to disable its auto title command. You can do that by uncommenting this line in your ~/.zshrc file:

DISABLE_AUTO_TITLE="true"
1
  • 6
    DISABLE_AUTO_TITLE="true" did the trick for me. Thank you. Dec 30, 2016 at 7:47
6

This should work regardless of the shell used:

printf "\033];%s\07\n" "hello world"
3

Earlier answers didn't quite work for me. Not without some hiccups (not always refreshed or something). It may be due to the fact I had ZSH, without oh-my-zsh. Fortunately I learned of chpwd, so:

chpwd() {
  [[ -t 1 ]] || return
  case $TERM in
    sun-cmd) print -Pn "\e]l%~\e\\"
      ;;
    *xterm*|rxvt|(dt|k|E)term) print -Pn "\e]2;%~\a"
      ;;
  esac
}
  1. chpwd gets called every time directory is changed.
  2. first time you launch xterm (or others) this doesn't count as directory change, so put chpwd call directly in .zshrc

As I do not use oh-my-zsh, I don't know if it works there, but unless they've changed and overwritten chpwd (in which case you will be overwriting their overwrite :D), it should.

0

It worked for me

TERM_TITLE=$'\e]0;**Terminal**\a'
1
  • Welcome to SuperUser! Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center Oct 23, 2022 at 15:42
-1

Well you can make a scrip that brings up a window and sets the name to be what you want. Execute the script to bring up the window with your name. You can also set the X,Y position and size of the window. You can make several and have windows named for every occasion.

2
  • // , Got anything a bit more specific? Mar 15, 2018 at 19:03
  • It has been over 12 years since I wrote those scripts. I do not want to give bad information but I think that all that was done using the options of xterm. Check the MAN page for xterm for more information. I may have the scripts somewhere, but Harvey has left all of my old disk in a pile where they were dumped to get them out of harms way. When repairs are complete I may be able to update this.
    – cliff2310
    Mar 16, 2018 at 22:57

You must log in to answer this question.

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