25

When I was using ubuntu 14.04, it's easy to set title. Just press F2 or move mouse to top menu. But there is no menu on ubuntu 16.04 and press F2 can't change the title. What should I do?

32

A lot of programs will overwrite the title so you can't rely on the title being fixed or not duplicated by other windows. This is especially so with remote ssh sessions in a gnome-terminal. It still helps a lot but its not reliable enough for window managers to do matching against (which is why I think they removed it. (addition by Amias Channer)) so this ability has been taken out with the newest gnome-terminal, however there is still a possibility to change the title, you can do it by command. To achieve this easily edit your ~/.bashrc file and add the following lines:

# function to set terminal title
function set-title(){
  if [[ -z "$ORIG" ]]; then
    ORIG="$PS1"
  fi
  TITLE="\[\e]2;$*\a\]"
  PS1="${ORIG}${TITLE}"
}

With this you then can set the title of your terminal window by simply using the command set-title <name you want to set it to>. This is possible due to ANSI escape codes so any program can output them regardless of where the code is run. That's what the \e and \a bits do. (addition by Amias Channer).

The solution I found here and using it myself since I run on 16.04 LTS.

  • 1
    A lot of programs will overwrite the title so you can't rely on the title being fixed or not duplicated by other windows. This is especially so with remote ssh sessions in a gnome-terminal. It still helps a lot but its not reliable enough for window managers to do matching against which is why I think they removed it. – Amias May 19 '16 at 7:31
  • 1
    If you like, the title is set by ANSI escape codes so any program can output them regardless of where the code is run – Amias May 19 '16 at 7:36
  • 2
    That's what the \e and \a bits do – Amias May 19 '16 at 7:36
  • 4
    Still, it's a bit arrogant to remove a useful feature - surely "we know what we're doing" !! – MikeW Dec 15 '16 at 14:21
  • 1
    2 hoots for the man.... Not only did he give a perfect solution, he also gave credits and references... Also attended to every query in the comments... More wins for all the good Samatirans in the world!! – Tanny Jun 15 '17 at 4:20
8

Videonauth's solution is bash-specific, meaning that if you use some other shell (such as korn shell or c shell or mksh or tcsh), it won't work. It also sets title via editing the PS1 prompt ( which for some reason has effect on the title in bash). Here's for example gnome-terminal with mksh:

enter image description here

What I personally use is this:

setTitle() {
    echo -e "\033]0;$@\007" 
}

This command uses escape sequences and is shell-agnostic , meaning this works in shells other than bash. Small downside is that you will need to know ASCII escape sequences if you want to tweak this.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.