Set Window Title in Bash

November 7, 2009 by Noah
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.


There are 2 comments on this page. Add yours.

Avatar image
tomekzet posted on August 6, 2009 @ 19:11 UTC

Simple and useful :)

Avatar image
Kuky posted on January 24, 2010 @ 16:52 UTC

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

Add a Comment

Used for your Gravatar and optional thread subscription. Privacy policy.
You may format your message using GitHub Flavored Markdown syntax.