GNU Screen auto title on gentoo

To automatically set widow title in GNU screen you can use PROMPT_COMMAND environment variable like it suggested here or here. Content of PROMPT_COMMAND will be executed by Bash before displaying command prompt.

On my gentoo default bashrc (/etc/bash/bashrc) already contains PROMPT_COMMAND rules, though for some reason they were not working correctly in my case.

1
2
3
4
5
6
7
8
case ${TERM} in
        xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix)
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
                ;;
        screen)
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
                ;;
esac

Another way of automatically setting screen title is by embedding special escape sequence into command shell prompt. The simplest way I found for achiving it is placing

PS1='\[\033k\033\\\]'$PS1

to the end of ~/.bashrc file.

Your screen’s shelltitle configuration parameter should be configured correctly according to your command prompt. For example if your prompt ends with $ than shelltitle could be “$ |bash”.

2 Responses

  1. This is no longer working. Busted butt all night long & all morning here and it’s still not working.

    Should be as simple as this, but it’s not.

    My guess, it’s broken.

    I can set the title using the escape, but something funky is going on with PS1 & PROMPT_COMMAND, even though I’ve cleared them to null (“”) and just used the basic initialization here.

    app-shells/bash-3.2_p33
    app-misc/screen-4.0
    x11-terms/rxvt-unicode-9.05-r2

  2. Works well for me with standard config files on Gentoo and Ubuntu.

Leave a Reply