17

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.

Jorge Castro
  • 73,717
chmullig
  • 273

6 Answers6

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.

5

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.

m0j0
  • 145
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"
djeikyb
  • 32,005
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
Mikel
  • 6,615
2

Add this to your ~/.screenrc

shell -$SHELL
Cam
  • 121
1

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

screen -T xterm

No need to modify any files.