# If not running interactively, don't do anything [ -z "$PS1" ] && return source colors function color_hash() { #shamelessly lifted from https://gist.github.com/377513 #slightly modified from the original hash_word=$1 num_of_colors=$2 Color=0 while [[ " 0 1 13 16 52 88 124 160 196 232 233 234 " == *\ ${Color}\ * ]]; do hash_word=$(echo $hash_word | cksum) hash_word=${hash_word%% *} Color=$(( ${hash_word} % $num_of_colors )) done echo $Color } function utime() { uptime | egrep -o -e "up [0-9]*.*[0-9]* user[s]?" | tr -s ' ' } function screens_count() { #doesn't catch named sessions, need to update echo -n `screen -ls | egrep -c "[0-9]+\.([a-zA-Z0-9\-]+)?\.[a-zA-Z]*"` } function disk_usage() { #pipe into awk '{print $3 }' for quantity used, $4 for quantity free, and $5 for percentage used df -h "`pwd`" | awk 'NR==2 { print $4 }' } function jobs_count() { echo -n `jobs | egrep -c \[[:digit:]+\]` } function screens_and_jobs_count() { # set -x all_jobs=`jobs_count` all_screens=`screens_count` results="" [ 0 -lt $all_screens ] && [ 0 -lt $all_jobs ] && echo -n " $all_screens screens, $all_jobs jobs |" && return [ 0 -lt $all_screens ] && [ 0 -eq $all_jobs ] && echo -n " $all_screens screens |" && return [ 0 -eq $all_screens ] && [ 0 -lt $all_jobs ] && echo -n " $all_jobs jobs |" && return # set +x } function free_memory() { echo -n `free -m | awk 'NR==3 { print $4"M" }'` } function laptop_battery() { if [ `hostname` = "hugin" ]; then on_ac_power || echo " `battmon2 -q` |" fi } if [ `id -u` -eq 0 ]; then PromptColor=${RedBG}${White} #red background for root else case $TERM in xterm*|screen*) PromptColor=$(color_hash $HOSTNAME 255) UserColor=$(color_hash $USER 255) x=x ;; linux*) PromptColor=$(color_hash $HOSTNAME 8) UserColor=$(color_hash $USER 8) ;; esac PromptColor="$(${x}bgcolor ${PromptColor})$(${x}fgcolor 0)" UserColor="${Normal}$(${x}fgcolor ${UserColor})" fi PS1='' export PS1='${PromptColor}`date +"%a %F, %T"` | `utime` |`screens_and_jobs_count` `disk_usage` | `free_memory` |`laptop_battery` ${UserColor}${USER}${PromptColor}@${HOSTNAME}:${PWD/$HOME/~}${Normal}\n> '