I haven't edited/created a .screenrc file in a while, but this is what I'm currently using:

# Turn off the screen startup message
startup_message off

# Define format of bottom navigation/status/date/etc. line
hardstatus alwayslastline "%{yk}[ %H ] %-Lw%50>%{gk}(%{-}%n-%t%{gk})%{-}%+Lw%< %=%{yk}[ %c %d.%m.%Y ]"

# Increase scrollback buffer to 30000 lines
defscrollback 30000

I honestly don't remember what everything in my hardstatus line stands for, but I want to figure out how I could change the hostname color based on the user that is logged in. Is this even possible? Right now, the hostname is yellow when I'm logged in under any user; but I want it to be red if I'm root. Is this something that can be changed in my .bashrc file? I have this in my .bashrc to change new screen window names to the hostname of the server I'm connected to:

# Set screen window title
case "$TERM" in
  PROMPT_COMMAND='echo -ne "\033k$HOSTNAME\033\\"'

Thanks for any help!


I've tried adding this to my .bashrc file, but it just puts the ANSI code in-front of the hostname in my screen hardstatus:

case "$TERM" in
  if (( $UID == 0 )); then
    PROMPT_COMMAND='echo -ne "\033k$FRED$HOSTNAME$RS\033\\"'
    PROMPT_COMMAND='echo -ne "\033k$HOSTNAME\033\\"'


I've also added the actual ANSI color codes (ex: \[\033[31m\]) and the screen escape codes (ex: %kr) to the above statement in my .bashrc, but neither worked.


If I use this as the prompt command line, the hostname appears in red in-front of my PS1:

PROMPT_COMMAND='echo -ne "\033[31m$HOSTNAME\033\\"'

If I use the following prompt, the window name changes to the hostname (YES!); but the color remains the default (NO!):

PROMPT_COMMAND='echo -ne "\033[31m\033k$HOSTNAME\033\\"'

I've also tried replacing \033[31m (and just [31m) with the screen color escape (%kr), but that did not work either.

  • You want to color it based on the user you're logged in as of if a certain user is logged onto the system?
    – slm
    Jan 28, 2013 at 14:31
  • Yes. I want to make it so the server hostname turns red when I log into that server as root. For example, in my .bashrc file, I have a line that changes my PS1 to all red text when I log in as root. I want to emulate this behavior with the hostnames in screen.
    – EGr
    Jan 28, 2013 at 14:36

1 Answer 1


Take a look at this U&L Q&A.

Specifically this answer, https://unix.stackexchange.com/a/16433/7453.

The general idea is that you maintain 2 different screenrc files with the colors and based on your $USER in your bashrc file you point the environment variableSCREENRC to the one for a given user.

  • I'll take a look. The only question I have regarding this is, will both .screenrc files work at the same time? For example, if I open screen as myself then sudo -s to root on another machine within that screen session, will my other screen windows stay yellow and the name (hostname) of the window I just became root in turn red?
    – EGr
    Jan 28, 2013 at 14:46
  • I don't know if that's possible, maybe it is, but it's still a bit too out of the ordinary, I mean, if you're inside the same screen session, it will be running using the same .screenrc. With two separate screen instances, it'd be plainly simple to do it, just two separate configs.
    – njsg
    Jan 28, 2013 at 14:56
  • That is what I assumed, I'll keep searching and update the thread if I find a solution (or if someone else has one). Thanks for the help!
    – EGr
    Jan 28, 2013 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.