#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2017 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 -c "^-" | tr -d " ")
	let hiddenfiles=$(ls -l -d .* | grep -c "^-" | tr -d " ")
	let executables=$(ls -l | grep -c ^-..x | tr -d " ")
	let directories=$(ls -l | grep -c "^d" | tr -d " ")
	let hiddendirectories=$(ls -l -d .* | grep -c "^d" | tr -d " ")-2
	let linktemp=$(ls -l | grep -c "^l" | tr -d " ")
	if [ "$linktemp" -eq "0" ]
	then
	    links=""
	else
	    links=" ${linktemp}l"
	fi
	unset linktemp
	let devicetemp=$(ls -l | grep -c "^[bc]" | tr -d " ")
	if [ "$devicetemp" -eq "0" ]
	then
	    devices=""
	else
	    devices=" ${devicetemp}bc"
	fi
	unset devicetemp

}

PROMPT_COMMAND=prompt_command

PS1="\n\
${color_separator}[ ${color_time}\$(date +%T) ${color_font}-${color_date} \$(date +%D) ${color_separator}]\
${color_separator}[ ${color_user}\u ${color_font}@ ${color_host}\h ${color_separator}]\
${color_separator}[ ${color_wdir}\${files}.\${hiddenfiles}-\${executables}x \$(systemkit dirsize) \
\${directories}.\${hiddendirectories}d\${links}\${devices}\
${color_separator} ][ ${color_uptime}\${loaddiff}${color_separator} ][ \
${color_ps}\$(ps ax | wc -l | sed -e \"s: ::g\")proc ${color_separator}]\
\n${color_separator}[ ${color_wdir}\$(truncpwd)${POW_1_COLOR}\$(POW_1) ${color_separator}]${color_font} \$ "
