new prompt (with screenshot)
so i was getting tired of the prompt i have / had and wanted a prompt that would give me more info. since i already had tmux giving me a decent amount of info i wanted to see if i could get my prompt to color code the load and give me the pwd.
after some searching on the google i stumbled upon this link.
so i butchered together this .bashrc:
#!/bin/bash function prompt_command { let prompt_line=${LINES} newPWD="${PWD}" } PROMPT_COMMAND=prompt_command function load_out() { echo -n "$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\1/" -e "s/ //g")" } function load_color() { gray=0 red=1 green=2 yellow=3 blue=4 magenta=5 cyan=6 white=7 tmp=$(echo $(load_out)*100 | bc) let load100=${tmp%.*} if [ ${load100} -lt 70 ] then tput bold ; tput setaf ${gray} elif [ ${load100} -ge 70 ] && [ ${load100} -lt 120 ] then tput bold ; tput setaf ${green} elif [ ${load100} -ge 120 ] && [ ${load100} -lt 200 ] then tput bold ; tput setaf ${yellow} elif [ ${load100} -ge 200 ] && [ ${load100} -lt 300 ] then tput bold ; tput setaf ${red} elif [ ${load100} -ge 300 ] && [ ${load100} -lt 500 ] then tput setaf ${gray} ; tput setab ${red} else tput bold ; tput setaf ${white} ; tput setab ${red} fi } PS1="\[\033[\${prompt_line};0H\]\[\e[30;1m\](\[\$(load_color)\]\$(load_out)\[\e[0m\]\[\e[30;1m\])-(\[\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\e[30;1m\])-> \[\e[0m\]"
what this snippet does:
anchors your prompt to the bottom of the term at all times using let prompt_line=${LINES}
it formats your prompt into 3 sections (load)-(pwd)-(dir files and size)
it gives you load uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\1/" -e "s/ //g"
it colorizes your load depending on the load as calculated in function load_color()
here is the screenshot with it running in conjunction to tmux:
as you can see in that screenshot, the load is at red.
like i said, most of this is not my work but the work of others that i have butchered together to get the results i wanted.
Leave a Reply