RFC: root/non-root bash prompts different colours?
Chris Adams
cmadams at hiwaay.net
Wed Dec 8 17:59:35 UTC 2004
Once upon a time, Richard June <rjune at bravegnuworld.com> said:
> Wow, that's ugly for both users and root.
> why not set root's foreground to blink?
Because blinking is damn annoying.
If anyone is going to do anything like this, please use tput to get
terminal capabilities before doing it (not everyone uses the same
terminal, not all terminals have color, and not all terminals use the
same escape sequences).
Something like:
colors=`tput colors`
if [ `id -un` = root ]; then
if ((${colors:-0} > 7)); then
standout=`tput setaf 5`
else
standout=`tput bold`
fi
else
if ((${colors:-0} > 7)); then
standout=`tput setaf 6`
else
standout=""
fi
fi
if [ "$standout" != "" ]; then
normal=`tput sgr0`
if ((${colors:-0} > 7)); then
other=`tput setaf 2`
else
other="$normal"
fi
if [ "$normal" = "" ]; then
standout=""
other=""
else
standout="\[$standout\]"
other="\[$other\]"
normal="\[$normal\]"
fi
fi
PS1="${other}[${standout}\u@\h \W${other}]\$${normal} "
unset standout other normal
--
Chris Adams <cmadams at hiwaay.net>
Systems and Network Administrator - HiWAAY Internet Services
I don't speak for anybody but myself - that's enough trouble.
More information about the fedora-devel-list
mailing list