Taking advantage of tab titles

If you're using many terminal tabs, you may have noticed that the default tab title does not particularly contribute to easy identification of the tab. user@hostname. It may make sense if your work mainly consists of administering systems remotely, which is frequently not the case.

This led me to adding this little snippet to my .bashrc files, resulting in nicer tab names:

  _set_xterm () { echo -ne "\e]0;$@\007"; }
  _clear_title () { _set_xterm shell; }
  _set_title ()
          # Ignore ourselves
          [ "$1" = _clear_title ] && return
          # Deal with job control
          if [ "$1" = fg ]
                  [ -n "$2" ] && MATCH="$(echo $2 |sed 's/^%\([0-9]*\)/^\\[\1\\]/')"
                  TITLE="$(jobs |grep "$MATCH" |sed 's/^[^ ]* *[^ ]* *//')"
          _set_xterm "$TITLE"
  trap 'set +o functrace; _set_title $BASH_COMMAND' DEBUG


Back to index...
First published
Fri Apr 24 09:46:37 2009
Last changed
Fri Apr 24 09:46:37 2009

Source code to the entries and scripts that format this site are available on github. Text of journal entries is licensed under CC-BY-SA license.

Mail questions, comments and pizza to lkundrak@v3.sk