Set Window Title in Bash

Noah Petherbridge
Posted by Noah Petherbridge on Friday, November 06 2009 @ 07:12:20 PM
Update (Nov 6 09): I found an even better way to do this and it emulates the way it works in DOS.

Just edit your .bashrc file and add this function to it:

# Allow the user to set the title.
function title {
PROMPT_COMMAND="echo -ne \"\033]0;$1 (on $HOSTNAME)\007\""
Now you can just do e.g. title IRC or whatever, and it would set the window title to IRC (on aerelon) if your hostname was aerelon like mine is (the hostname is handy if you work with multiple servers).

Now, the original post follows:

This is a small script I wrote that allows you to set a custom window title on your bash shells. It works in most sane bash terminal emulators (gnome-terminal and XFCE's Terminal for sure, Konsole likely, xterm likely...)

It works kinda, sorta like the DOS `title` command, except it doesn't take your title on the command line and instead prompts for it after you run the command.

Installation is in 2 parts:

1) The bash script, which you put in your home directory's "bin" folder (eg /home/kirsle/bin) - make the folder if it doesn't exist.


echo -n "Title: "
read -e TITLE
PROMPT_COMMAND='echo -ne "\033]0;$TITLE\007"'
2) The bash alias. Setting a title manually involves typing that last line (PROMPT_COMMAND) into the terminal directly (with an actual title in place of $TITLE); it sets the environment variable PROMPT_COMMAND, which ensures your custom title sticks. Bash scripts aren't allowed to modify your environment variables by default. So, set an alias to this command that, instead of executing it, sources it instead.

Edit your .bashrc file (eg. /home/kirsle/.bashrc):

alias title='. /home/kirsle/bin/title'
Now reload your .bashrc file with the command `. ~/.bashrc` or start a new bash shell, type in the word `title` and hit enter, and enter a title when prompted.


[ Blog ]


There are 2 comments on this page.

Posted on Thursday, August 06 2009 @ 12:11:44 PM by tomekzet.

Simple and useful :)

Posted on Sunday, January 24 2010 @ 08:52:19 AM by Kuky.

I just like to say that this page looks very nice and that I am amazed that is strict.dtd!

Add a Comment

Your name:
Your Email:
Comments can be formatted with Markdown, and you can use
emoticons in your comment.

If you can see this, don't touch the following fields.

Web Tools

Fan Club