Friday, May 10, 2013

How to change the title of an xterm

  • ESC]0;stringBEL – Set icon name and window title to string
  • ESC]1;stringBEL – Set icon name to string
  • ESC]2;stringBEL – Set window title to string
An xterm title of username@hostname: directory:
    echo -n "\033]0;${USER}@${HOST}\007"

For bash
    case $TERM in
        xterm*)
            PS1="\[\033]0;\u@\h: \w\007\]bash\\$ "
            ;;
        *)
            PS1="bash\\$ "
            ;;
    esac

For zsh
    case $TERM in
        xterm*)
            precmd () {print -Pn "\e]0;%n@%m: %~\a"}
            ;;
    esac