I've been mucking with my .bashrc file in Gentoo so I might have the username in PS1 change color according to system load, but it's not quite working. When I can get it to stop throwing errors, the color is red when load is 0, and most of the time, bash throws errors (when load is 0, andyway). Here's my bashrc (the modified parts):

Code:

function promptmodify
{
local USRCOLOR=""
local FLOAD=$(echo $(uptime | awk '{print $10}'))
local LOAD=$(echo $FLOAD | awk -F . -- '{print $2}')
if [ $(echo $LOAD | awk -F 0 -- '{print $1}') == "0" ]; then
        LOAD="$(echo $LOAD | awk -F 0 -- '{print $1}')"
fi

if [ $LOAD >= 100 ]; then
        USRCOLOR="\[\033[1;31m\]" #bright red
elif [[ $LOAD<80 && $LOAD<100 ]]; then
        USRCOLOR="\[\033[0;33m\]" #dull red
elif [[ $LOAD>50 && $LOAD<81 ]]; then
        USRCOLOR="\[\033[0;33m\]" #dull yellow
elif [[ $LOAD>20 && $LOAD<51 ]]; then
        USRCOLOR="\[\033[0;32m\]" #dull green
elif [ $LOAD<21 ]; then
        USRCOLOR="\[\033[1;34m\]" #bright blue
fi
export PS1="${USRCOLOR}\u${GREEN}@\w\$${GREY} "
}
promptmodify

It's telling me '[: ==: unary operator expected' and '[: 00: unary operator expected', still with system load at 0. Any help?

And just for kicks, anyone else customized their prompt?
I have modified my prompt, although not much beyond the standard. However, I'm guessing you are going to have a problem with this anyway. As I understand it, .bashrc is only read upon initial execution of the bash shell, which means your custom PS1 will be set only once - and not updated continuously or even on every new input prompt, so I'm not sure how your colorized load would work anyway. It has been a while since I have programmed in BASH, though, so I have no idea why it is throwing an error.

Next time I am in Gentoo I will have to check it out and see what I can dig up (I'm on my laptop right now, which is Vista only - not really enough hard drive space to be able to partition it).
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement