Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I arbitrarily change the title of a Terminal window in Mac OS X? I have seen this question and this magicwrap thing, but think it's just a simple Mac OS X command.

share|improve this question
    
Should note that there's nothing OS X specific about this -- the answer will work on pretty much any terminal. –  Andrew Aylett Feb 6 '10 at 11:22
    
Is it Bash-specific then? –  Yar Feb 6 '10 at 14:55
    
@Andrew Aylett, so the script I put in my answer (below) will work on the linux distros, too? –  Yar Feb 6 '10 at 18:20
    
Yes, it should work anywhere (with an sh-derived shell) that uses unix-y terminals. –  Andrew Aylett Feb 11 '10 at 22:02

4 Answers 4

up vote 23 down vote accepted

This article tells you how.

Essentially, you use character sequences echoed to the screen to inform the terminal of what title it should display.

title='My first title'
echo -n -e "\033]0;$title\007"

In the above example, whatever the variable title is set to while become the terminal's title. Of course, you could just have the title in the string to echo such as:

echo -n -e "\033]0;My first title\007"

But the first way makes it just that slightly bit easy to user and/or extend later.

share|improve this answer
    
Excellent. Could you include a sample script (like this? echo -n -e "\033]0;$1\007") in your answer so I can mark it best answer, please? –  Yar Feb 6 '10 at 9:15
2  
printf may be more reliable: printf "\033]0;%s\007" "$title_variable" (the various options and behaviors of echo are not the same across all systems, shells, or even shell options) Also, variable assignments in bash should not have spaces around the equals sign. –  Chris Johnsen Feb 6 '10 at 12:03

Remix of Dan MgG's answer:

echo -n -e "\033]0;$1\007"

Store it in a file called /usr/bin/title (using sudo!) and chmod it to +x. Then from anywhere you can just type

title 'Trying to Figure This GIT Thing Out'

and you get a nice little title.

(Syntax may vary if you're not on OSX, if I understand correctly)

share|improve this answer

Adding the following to your ~/.profile will achieve the same effect:

# function for setting terminal titles in OSX
function title {
  printf "\033]0;%s\007" "$1"
}

And then a quick title 'et voila' will sort all your tabs out.

share|improve this answer
    
Thanks, the code is cool, the problem is that I have a million things that could be functions. BTW, if you use community wiki, you don't get the points :( –  Yar Apr 17 '10 at 12:31
    
why is it a problem if you have many functions in .profile? is there a limit? –  tgkprog Jun 4 '13 at 14:22
    
IDK why, but had to edit .bash_profile instead of .profile –  Nakilon Sep 8 '13 at 23:45

Thanks for this. I just added a function to my .bashrc:

    function stit() {
    echo -n -e "\033]0;$1\007"
}

In my mind "stit" = a convenient shortcut for "set_title". And now when I want to set the title of my windows on the fly, I type:

stit "[new window title]"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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