Retaining bash prompt colors when starting a screen session
Solution 1
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.
Solution 2
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. 🙂
Solution 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:
[email protected]:~$ 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"
Solution 4
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
Solution 5
Add this to your ~/.screenrc
shell -$SHELL
Related videos on Youtube

chmullig
Updated on September 17, 2022Comments
-
chmullig 5 months
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;\[email protected]\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
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 thisls -al
are blue) but the prompt isn't. In theory everything should be exactly the same. $PS1 inside screen:${debian_chroot:+($debian_chroot)}\[email protected]:\w\$
EDIT: This is just plain vanilla screen.
-
belacqua almost 12 yearsIs this plain vanilla screen, or do you have byobu installed? (Though this matter not matter.)
-
Mikel almost 12 yearsDoes
echo $PS1
print the same thing inside screen and outside screen? -
chmullig almost 12 years$PS1 is indeed different. Edited question to include that.
-
-
chmullig almost 12 yearsPerfect, 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!
-
Adam Ryczkowski over 10 yearsThe change needs to be done on the server machine, not the client.
-
funroll about 9 years+1. This got me back my nice looking bash prompt on OS X.
-
phi over 2 yearsThis looks like the cleanest way to enable color for screen sessions.
-
Rémy Hosseinkhan Boucher 11 monthsNice, allows to keep host color with GNU Screen in local.