#!/bin/zsh
setopt no_unset extended_glob

SED_SCRIPT='
s/^run:/%F{green}↑/;
s/^down:/%F{red}↓/;

s/ run/\%F{green}\0/g;
s/ down/%F{red}\0/g;

s/: /%f\0/g;
s/$/%f/;
'

for pid in $(pgrep runsvdir); do
	a=( ${(0)"$(</proc/$pid/cmdline)"} )
	if [[ "$a[2]" == -* ]]; then
		d=$a[3]
	else
		d=$a[2]
	fi
	d="${d%/}"
	if [[ -d $d ]]
		services=( $d/*/supervise(FN) )
		(( $#services )) && sv stat $services:h
done | sed "${(%)SED_SCRIPT}"