# Set your xterm/konsole/other terminal title

## phong

I put this in my /etc/profile:

```
if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]

then

        if [ "$TERM" = 'xterm' ]

        then

                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'

        fi

fi
```

Works quite nicely so I know where all my terminals are at from the taskbar.

----------

## kaffee

Zsh users can utilize precmd() to achieve the same. For example:

```

if [ $TERM = xterm ]; then

  precmd () {

    print -Pn "\e]0;[ %/ ]\a"

  }

fi

```

----------

## buckminst

It should be noted that some terminal emulators don't identify themselves as 'xterm'... case in point being aterm... you would need to modify the code thusly:

```

if [ "$TERM" = 'xterm' ] || [ "$TERM" = 'rxvt' ]

```

Everything else would be the same.

----------

## itsr0y

 *kaffee wrote:*   

> Zsh users can utilize precmd() to achieve the same.

 

In fact, with zsh, you can set the term title to be the path when you are at a prompt, and to the current command when a program is running:

```
case $TERM in

     *xterm*|rxvt|(dt|k|E)term)

          precmd () { print -Pn "\e]0;$TERM - %~\a" }

          preexec () { print -Pn "\e]0;$TERM - $1\a" }

          ;;

esac

```

You can modify the $TERM - %~ and $TERM - $1 as needed.  See http://www.acm.uiuc.edu/workshops/zsh/prompt/escapes.html for a full list of stuff to put in the prompt (or title).

----------

## barmaley

This version will substitute user's home directory with a tilde:

```
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
```

----------

## vbenares

I recognize this thread is dead, but  . . .  

Is there any way to identify in the title bar whether one has su'ed or not?

----------

## barmaley

Of course! If you do 'su -', the version above will display root@host. However, if you do su without '-', it won't, because bash profile is not sourced and $USER contains the old value.

If it's not enought, you have at least the following two possibilities:

- insert `whoami` instead of ${USER}

- place a condition in your .bashrc and set custom PROMPT_COMMAND depending on the value of `whoami`, like this:

```

case `whoami` in

    root)

        PROMPT_COMMAND='echo -ne "\033]0;---root---\007"'

        ;;

    *)

        PROMPT_COMMAND='echo -ne "\033]0;---non-root---\007"'

        ;;

esac

```

This is the code from my real bash config:

```

case `whoami` in

    root)

        USER_AT_HOST="# ${USER}@${HOSTNAME%%.*}"

        ;;

    *)

        USER_AT_HOST="${USER}@${HOSTNAME%%.*}"

        ;;

esac

case $TERM in

    xterm*|rxvt|eterm)

        PROMPT_COMMAND='echo -ne "\033]0;${USER_AT_HOST}: ${PWD/$HOME/~}\007"'

        ;;

    screen)

        PROMPT_COMMAND='echo -ne "\033_${USER_AT_HOST}: ${PWD/$HOME/~}\033\\"'

        ;;

esac

```

----------

## vbenares

This is totally cool.

----------

## ed0n

in gnome-terminal which I use is to easy and simple to change it , you can change it by change-ing the profile . 

But sometimes I also use xterm and this looks cool

thank you phong

----------

## shm

with konsole, you can even set the name of the tab using dcop:

I use this:

 *Quote:*   

>  A="$PWD"
> 
> PROMPT_COMMAND='echo -ne $A; dcop $KONSOLE_DCOP_SESSION renameSession $A' 

 

I also put this in .vimrc to set the tab to vim's current file

```

autocmd BufReadPost * :silent !dcop $KONSOLE_DCOP_SESSION renameSession %

```

----------

## varnyu

hi,

is there any solution for displaying the current running process in the titlebar using bash? (like emerge does)

thanks

----------

## kernelcowboy

Yeah, would like to hear the answer to this !BUMP!  This is one old thread.  :Razz: 

----------

## Zentoo

!bump 2!

  I'm looking the way to do the same too ! I whish my script could update title for chroot environment to make the difference between chrooted environment and normal one.

----------

## shadeheim

bump

----------

