15

When I ssh into a Ubuntu Lucid box the prompt is all pretty, with colors. Everything is the default, as far as I know. Here's my $PS1 outside screen:

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@dev\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

Before connecting with screen

But then once I start screen up the colors go away. Everything else is fine, and my screen can support colors (notice that the . and .. in this ls -al are blue) but the prompt isn't. In theory everything should be exactly the same. $PS1 inside screen:

${debian_chroot:+($debian_chroot)}\u@dev:\w\$

after screening in

EDIT: This is just plain vanilla screen.

3
  • Is this plain vanilla screen, or do you have byobu installed? (Though this matter not matter.)
    – belacqua
    Feb 4, 2011 at 5:08
  • 2
    Does echo $PS1 print the same thing inside screen and outside screen?
    – Mikel
    Feb 4, 2011 at 10:41
  • $PS1 is indeed different. Edited question to include that.
    – chmullig
    Feb 4, 2011 at 16:03

6 Answers 6

20

You can edit the following line in your .bashrc (it's #39 in my .bashrc):

#force_color_prompt=yes

Change to:

force_color_prompt=yes

This could possibly be annoying if you log in from somewhere where color is not supported, but i find it highly unlikely.

3
  • Perfect, that did it for me. I can see it being problematic if I happen to login from somewhere without color, but that's going to be pretty rare. Thanks!
    – chmullig
    Feb 4, 2011 at 16:04
  • The change needs to be done on the server machine, not the client. Oct 27, 2012 at 9:36
  • Nice, allows to keep host color with GNU Screen in local. Mar 23, 2022 at 16:42
4

Screen normally uses a special terminal type, such as "screen", or if you set it in your .screenrc, "screen-256color".

Just look in your .bashrc for the color detection case statement and add screen to the list.

For example, something like this:

case "$TERM" in
    xterm)
        color_prompt=yes
        ;;
    screen)
        color_prompt=yes
        ;;
    *256*) 
        color_prompt=yes
        ;;
esac

I use 256-color terminal types, so I just need the 256 case statement, since it catches xterm-256color, gnome-256color, and screen-256color. Your mileage may vary. 🙂

1
  • 1
    This looks like the cleanest way to enable color for screen sessions.
    – phi
    Sep 22, 2020 at 15:41
3

The .screenrc file is a mystery to me. Mine is gobbledygook that I copypasta'd from the internets. However, I see a few lines that look to be relevant to your problem:

# terminfo and termcap for nice 256 color terminal
# allow bold colors - necessary for some reason
attrcolor b ".I" 
# tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'

I think if you add the above lines to yours, you'll get colour. Here's my whole .screenrc for reference:

jake@daedalus:~$ cat .screenrc 
startup_message off # skip splash screen
vbell off # Kill the annoying dog

# Voodoo
hardstatus alwayslastline
hardstatus string '%{= wk}%-Lw%{= KW}%50>%n%f* %t%{= dK}%+Lw%<'

# terminfo and termcap for nice 256 color terminal
# allow bold colors - necessary for some reason
attrcolor b ".I" 
# tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
# erase background with current bg color 
defbce "on"
2

Your PS1 setting should be placed in .bashrc, not .bash_profile.

If that is not the problem, please edit your question to include the line you have set PS1 to.

You could also try running these:

echo "$TERM"                                 # will probably print "screen"
tput setaf 2 | cat -vte                      # should print "^[[32m"
echo "$(tput setaf 2)"green"$(tput sgr0)"    # should print "green" in green
2

Add this to your ~/.screenrc

shell -$SHELL
2
  • +1. This got me back my nice looking bash prompt on OS X.
    – funroll
    Dec 5, 2013 at 19:10
  • @Cam , it works on a HPC, what does it does ? Jan 30 at 16:39
1

Invoking screen with -T xterm works for me, so simply:

screen -T xterm

No need to modify any files.

You must log in to answer this question.

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