Naming your Terminal tabs in OSX Lion

If you find yourself in the Terminal app with a bunch of tabs open, the default name of “bash” isn’t very useful when navigating between them. You can change the tab name via the UI by right clicking the tab, then clicking “Inspect Tab” and changing the window or tab names but this is somewhat long winded.

Below are a couple of bash functions I have in my “.profile” file to make this easier:

function tabname {
  printf "\e]1;$1\a"
}
 
function winname {
  printf "\e]2;$1\a"
}

Now you can easily name your tabs or windows with the following:

# Rename tab
tabname "Funky Tab"
 
# Rename window
winname "Funky Window"

Thanks to Bubu and Chris Page on the SuperUser site for the right codes.

Tags: , , , ,

4 comments

  1. Nice one, I’ve put that straight in my .profile

  2. I’ve even put this into my PS1, so if any program changes it (e.g. VIM), when execution returns to shell, the title will be restored.

    export PS1=”\[\e]1;${XTERM_TITLE:-\u@\h:\w}\a\]\u@\h:\w”

    title() {
    export XTERM_TITLE=”$@”
    }

    Don’t forget to surround your title ASCII sequence inside PS1 with \[ \] pair or you will get wrong command prompt display in some cases.

  3. Nicky Parseghian

    Cool little command. Adopted!

  4. CMD + I also gets you the inspector window, pressing CMD + I again closes the window or you can press CMD + W as usual.

Leave a comment