Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I do that in bash for root/non-root users (root is red, non-root is blue):

    if [[ ${EUID} == 0 ]] ; then
        PS1='\[\033[01m\][ \[\033[01;31m\]\u@\h \[\033[00m\]\[\033[01m\]] \[\033[01;32m\]\w\[\033[00m\]\n\[\033[01;31m\]\$\[\033[00m\]> '
    else
        PS1='\[\033[01m\][ \[\033[01;34m\]\u@\h \[\033[00m\]\[\033[01m\]] \[\033[01;32m\]\w\[\033[00m\]\n\[\033[01;34m\]\$\[\033[00m\]> '
    fi
Interesting to think about using it across servers, though.


I used to have a different prompt color when SSH_CONNECTION was in my environment, to distinguish local terminals from remote connections. And also root/non-root, although I didn't know about $EUID and used the less-effective $(id -u).


Konsole does this automatically, at least on openSuSE linux.


It's actually just the default bash config on openSUSE, nothing to do with Konsole. It works on text-mode VTs, via ssh, etc.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: