Hacker News new | past | comments | ask | show | jobs | submit login
Set the title of a bash terminal on OS X (datasyndrome.com)
2 points by rjurney on Dec 31, 2011 | hide | past | favorite | 1 comment



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:

  printf "\033]1;icon title\033\\"
  printf "\033]2;window title\033\\"
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:

  chpwd () {
    printf "\033]0;[${HOST}] ${PWD}\033\\"
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: