dtfscript: Implement service logging coloration
This commit is contained in:
		@@ -14,17 +14,27 @@ service_flags=""
 | 
			
		||||
# Basic logging service. Do not override unless necessary
 | 
			
		||||
function svc_log() {
 | 
			
		||||
	if [ -z ${1+x} ]; then return 1; fi
 | 
			
		||||
	dtf_log "$service_name: $1"
 | 
			
		||||
	out=1
 | 
			
		||||
	if ! [ -z ${2+x} ]; then out="$2"; fi
 | 
			
		||||
	col_reset="\e[0m"
 | 
			
		||||
	col_svcname="\e[94m"
 | 
			
		||||
	col_message="\e[39m"
 | 
			
		||||
	if ! [ "$out" -eq "1" ]; then col_message="\e[31m"; fi
 | 
			
		||||
	if [ "$out" -eq "0" ]; then
 | 
			
		||||
		out=1
 | 
			
		||||
		col_message="\e[37m"
 | 
			
		||||
	fi
 | 
			
		||||
	dtf_log "${col_svcname}${service_name}${col_reset}: ${col_message}${1}${col_reset}" >&${out}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Basic pre-start checks. Stick extra checks in prestart-extra
 | 
			
		||||
function prestart() {
 | 
			
		||||
	if pgrep $service_process > /dev/null 2>&1; then
 | 
			
		||||
		svc_log "Already running"
 | 
			
		||||
		svc_log "Already running" 0
 | 
			
		||||
		return 1
 | 
			
		||||
	fi
 | 
			
		||||
	if ! which $service_process > /dev/null 2>&1; then
 | 
			
		||||
		svc_log "Could not find associated binary: \"${service_process}\""
 | 
			
		||||
		svc_log "Could not find associated binary: \"${service_process}\"" 2
 | 
			
		||||
		return 1
 | 
			
		||||
	fi
 | 
			
		||||
	return 0
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ service_process="sxhkd"
 | 
			
		||||
 | 
			
		||||
function prestart-extra() {
 | 
			
		||||
	if ! pgrep bspwm > /dev/null 2>&1; then
 | 
			
		||||
		svc_log "Not under bspwm"
 | 
			
		||||
		svc_log "Not under bspwm" 2
 | 
			
		||||
		return 1
 | 
			
		||||
	fi
 | 
			
		||||
	return 0
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ service_process="compton"
 | 
			
		||||
 | 
			
		||||
function prestart-extra() {
 | 
			
		||||
	if [[ "$HOST" == "vm-*" ]]; then
 | 
			
		||||
		svc_log "Will not start: in a VM"
 | 
			
		||||
		svc_log "Will not start: in a VM" 2
 | 
			
		||||
		return 1
 | 
			
		||||
	fi
 | 
			
		||||
	return 0
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ function start-extra() {
 | 
			
		||||
		if xprop -name "Conky" > /dev/null 2>&1; then break; fi
 | 
			
		||||
		sleep 0.01
 | 
			
		||||
		if (( $i > 99 )); then
 | 
			
		||||
			svc_log "Conky may spawn behind the current desktop"
 | 
			
		||||
			svc_log "Conky may spawn behind the current desktop" 2
 | 
			
		||||
			break
 | 
			
		||||
		fi
 | 
			
		||||
	done
 | 
			
		||||
 
 | 
			
		||||
@@ -20,8 +20,8 @@ function start() {
 | 
			
		||||
	# Spawn bars on the primary monitor
 | 
			
		||||
	export PB_MONITOR=$(xrandr -q | awk '/primary/{print $1}')
 | 
			
		||||
	svc_log "Starting primary on monitor $PB_MONITOR"
 | 
			
		||||
	polybar -r primary& > /dev/null 2>&1
 | 
			
		||||
	polybar -r primary-2& > /dev/null 2>&1
 | 
			
		||||
	polybar -r primary& >/dev/null 2>&1
 | 
			
		||||
	polybar -r primary-2& >/dev/null 2>&1
 | 
			
		||||
 | 
			
		||||
	# Spawn more for each secondary
 | 
			
		||||
	export secondary_monitors=$(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}')
 | 
			
		||||
@@ -31,8 +31,8 @@ function start() {
 | 
			
		||||
	for monitor in $secondary_monitors; do
 | 
			
		||||
		svc_log "Starting secondary on monitor $monitor"
 | 
			
		||||
		PB_MONITOR=$monitor
 | 
			
		||||
		polybar -r secondary& > /dev/null 2>&1
 | 
			
		||||
		polybar -r secondary-2& > /dev/null 2>&1
 | 
			
		||||
		polybar -r secondary& >/dev/null 2>&1
 | 
			
		||||
		polybar -r secondary-2& >/dev/null 2>&1
 | 
			
		||||
	done
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user