#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2010 Christopher Bratusek		#
#							#
#########################################################

function prompt_command
{

local one=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g")
local five=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\2/" -e "s/ //g")
local diff1_5=$(echo -e "scale = scale ($one) \nx=$one - $five\n if (x>0) {print \"up\"} else {print \"down\"}\n print x \nquit \n" | bc)
loaddiff="$(echo -n "${one}${diff1_5}" | sed -e 's/down\-/down/g')"

let files=$(ls -l | grep "^-" | wc -l | tr -d " ")
let hiddenfiles=$(ls -l -d .* | grep "^-" | wc -l | tr -d " ")
let executables=$(ls -l | grep ^-..x | wc -l | tr -d " ")
let directories=$(ls -l | grep "^d" | wc -l | tr -d " ")
let hiddendirectories=$(ls -l -d .* | grep "^d" | wc -l | tr -d " ")-2
let linktemp=$(ls -l | grep "^l" | wc -l | tr -d " ")
if [ "$linktemp" -eq "0" ]
then
    links=""
else
    links=" ${linktemp}l"
fi
unset linktemp
let devicetemp=$(ls -l | grep "^[bc]" | wc -l | tr -d " ")
if [ "$devicetemp" -eq "0" ]
then
    devices=""
else
    devices=" ${devicetemp}bc"
fi
unset devicetemp

}

PROMPT_COMMAND=prompt_command

if [[ $enabcol == true ]]; then

PS1="\n\
$sepacolor[ $timecolor\$(date +%T) $fontcolor-$datecolor \$(date +%D) $sepacolor]\
$sepacolor[ $usercolor\u $fontcolor@ $hostcolor\h $sepacolor]\
$sepacolor[ $wdircolor\${files}.\${hiddenfiles}-\${executables}x \$(show_size) \
\${directories}.\${hiddendirectories}d\${links}\${devices}\
$sepacolor ][ $upcolor\${loaddiff}$sepacolor ][ \
$pscolor\$(ps ax | wc -l | sed -e \"s: ::g\")proc $sepacolor]\
\n$sepacolor[ $wdircolor\$(trunc_pwd)$POW_1_COLOR\$(POW_1) $sepacolor]$fontcolor \$ "

else

PS1="\n\
[ \$(date +%T) - \$(date +%D) ]\
[ \u @ \h ]\
[ \${files}.\${hiddenfiles}-\${executables}x \$(show_size) \
\${directories}.\${hiddendirectories}d\${links}\${devices}\
][ \${loaddiff} ][ \
\$(ps ax | wc -l | sed -e \"s: ::g\")proc ]\
\n[ \$(trunc_pwd)\$(POW_1) ] \$ "

fi
