Note that the "beep" terminator is antiquated; xterm relies on a universal string terminator of an escaped backslash, i.e. "\033\\" in this syntax instead of "\007". (Also nicer since it won't beep in terminals that don't support it.)
The "0;" means "set both icon and window title"; you can also make this "1;" to set the icon title only (i.e. when minimized) and "2;" to set the window title only (i.e. when not minimized). For example:
If your terminal supports this, you'll see "icon title" when the window is minimized (e.g. in the Dock on Mac OS X) and "window title" otherwise.
If you want to do this in any Bourne-compatible shell and not just "bash", try omitting the "function" word. And if your system does not have an "echo" that supports these options, see if the "printf" command is available and use that instead. For example:
settitle() {
printf "\033]0;$1\033\\"
}
There are other tricks, e.g. I use "zsh" and in my ".zshrc" this causes the window title to show the hostname and current directory path any time "cd" is used:
The "0;" means "set both icon and window title"; you can also make this "1;" to set the icon title only (i.e. when minimized) and "2;" to set the window title only (i.e. when not minimized). For example:
If your terminal supports this, you'll see "icon title" when the window is minimized (e.g. in the Dock on Mac OS X) and "window title" otherwise.If you want to do this in any Bourne-compatible shell and not just "bash", try omitting the "function" word. And if your system does not have an "echo" that supports these options, see if the "printf" command is available and use that instead. For example:
There are other tricks, e.g. I use "zsh" and in my ".zshrc" this causes the window title to show the hostname and current directory path any time "cd" is used: