13

When I run screen it changes my prompt. How do I prevent this behaviour? For example:

$ echo $PS1
\[\e]0;\h:Prod\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$
$ screen
$ echo $PS1
[\u@\h \W]\$

Interestingly, it does not do this on other machines. The machine in question is Redhat 4 update 4, with Screen version 4.00.02 (FAU) 5-Dec-03.

4 Answers 4

16

Try adding (assuming it's not already there) to your .screenrc file:

shell -$SHELL

This will give you a login shell when you initialize a screen session or create another terminal from within one.

1
  • 1
    I had 'shell /bin/bash' in my .screenrc, apparently it should have been 'shell -/bin/bash' or what you provided.
    – Swoogan
    Jul 23, 2009 at 18:37
2

Many distributions check the type of terminal before setting the prompt. Ubuntu, for example, contains this little gem in the default .bashrc:

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

Since screen uses its own TERM variable ("screen"), bash thinks it's not capable of displaying a fancy color prompt so it defaults to a simpler one. Screen is, of course, fully capable of the same complex prompts as a normal terminal.

So, to override this behavior, just hard-set your preferred PS1 options at the end of your ~/.bashrc file. Or, if you're feeling adventurous, find the test that checks the value of the TERM variable and modify it to accept "screen" in addition to "xterm-color".

1

Perhaps this is a customized variable that is set in the ~/.screenrc file?

2
  • 1
    Yes, check for setenv PS1 in global or personal screenrc
    – radius
    Jul 23, 2009 at 17:33
  • 4
    And what customized variable would that be? If you don't know the answer, don't answer.
    – Swoogan
    Jul 23, 2009 at 18:35
0

Had the same issue (no more custom prompt in screen) on a machine with SHELL -$SHELL and no setenv PS1 in screenrc, and no special test for (dumb) terminal in bashrc.

Setting the used $TERM:

$ echo $TERM
urxvt-unicode-256color

in screenrc got my custom prompt back while under Screen:

- #term xterm-256color
+ term urxvt-unicode-256color

PS: another account had no need for this, but bashrc tests for dircolors and a modern terminal this way1:

if [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] ; then
PS1=<my fancy prompt>

I believe this works as well:

if [ "$TERM" != "dumb" ]; then
PS1=<my fancy prompt>

Not the answer you're looking for? Browse other questions tagged .