alias to retitle current gnome-terminal

In a gnome-terminal (bash) I can run this command to change the title of the terminal to "hello":

PROMPT_COMMAND='echo -ne "\033]0;hello\007"'

That's great, but now I want to create an alias named "title" in ~/.bashrc to run that command so that I can open any terminal and just type "title" and have the terminal window's name change to "hello".

What is the code that will create the alias so that it works? I'm sure it's a maze of character escape sequences.

Extra bonus points if you can code it so that I can type in something like "title My Window" and the alias will then title the current gnome-terminal to "My Window".


The rule of thumb about aliases is that if you have to ask, you should use a function instead:

title() {
  printf "\033]2;%s\007" "$*"
title "This is my title"

that other guy's answer helped. The final solution that worked was adding the following code to .bashrc

function title(){
    PROMPT_COMMAND='echo -ne "\033]0;'"$1"' '"$2"' '"$3"'\007"'
export -f title

Need Your Help

Attempting to learn polymorphism, etc. in VB6, but my code doesn't do what I want it to

vb6 parameters polymorphism

Here's what I've got on a command button; it's just creating variables and attempting to output their ID (which should be an instance variable inherited from the base class.)